Skip to content

RecursionError when loading GLB file with deeply nested JSON in Mesh feature #8246

Description

@BeyondBirthday07

Description

Loading a GLB file with deeply nested JSON chunk causes a RecursionError, crashing the application.

Step to Reproduce

from datasets import Dataset, Mesh
import tempfile, os, struct

def make_malicious_glb(depth=5000):
    json_chunk = (b'{"a":' * depth + b'1' + b'}' * depth)
    magic = b'glTF'
    version = struct.pack('<I', 2)
    json_len = struct.pack('<I', len(json_chunk))
    json_type = struct.pack('<I', 0x4E4F534A)
    total_len = 12 + 8 + len(json_chunk)
    length = struct.pack('<I', total_len)
    return magic + version + length + json_len + json_type + json_chunk

glb_bytes = make_malicious_glb(depth=5000)

with tempfile.TemporaryDirectory() as tmpdir:
    fpath = os.path.join(tmpdir, 'test.glb')
    with open(fpath, 'wb') as f:
        f.write(glb_bytes)
    
    ds = Dataset.from_dict({'mesh': [fpath]}).cast_column('mesh', Mesh())
    result = ds[0]['mesh']

Expected: Proper error message
Actual: RecursionError crash

Suggested Fix

Catch RecursionError in Mesh.decode_example() and raise ValueError instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions