Skip to content

ped_assemble: a malformed GLB is one ERROR line and exit 2, not a traceback - #5999

Closed
enzo-billis wants to merge 2 commits into
ItsNotRexed:mainfrom
enzo-billis:ped-assemble-malformed-glb
Closed

enzo-billis wants to merge 2 commits into
ItsNotRexed:mainfrom
enzo-billis:ped-assemble-malformed-glb

Conversation

@enzo-billis

@enzo-billis enzo-billis commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #5934 (comment) (new BUILD item, no ID yet)

What and why

tools/ped_assemble.py ended in a Python traceback on a malformed GLB. On main 561b65a83, ped_assemble.py assemble x.glb -o out.glb:

input main
a material that is not an object AttributeError: 'int' object has no attribute 'get'
a pbrMetallicRoughness that is not an object AttributeError: 'list' object has no attribute 'get'
a BIN chunk shorter than its accessors need struct.error: unpack_from requires a buffer of at least 62 bytes ...
a node (or, without one, mesh) name that is not text TypeError: expected str, bytes or os.PathLike object, not int

read_glb_parts walked the document without checking it. _check_glb_document now runs before the part loop and checks only what the reader dereferences: the tables it indexes, the accessors its primitives name (component type, accessor type, and that their bytes are inside the BIN chunk), the material fields it converts and the name it gives the part. A JSON chunk that does not parse is the same kind of error. Each case is ERROR: <path>: malformed GLB: <what> and exit 2.

What the reader read before, it still reads, with tests: a document with no nodes, a material index past the table, a primitive without POSITION, an accessor nothing reads, numbers written as strings that float() takes, a count / byteOffset / byteStride written as a whole float (3.0, which the reader's int() always took), a falsy node name (falls back to the mesh's) and a non-text mesh name the node's name overrides.

Stricter than main, on inputs that crashed or read wrong data:

  • a mesh node's translation must have exactly 3 numbers;
  • an attribute's accessor must have the type the reader assumes (POSITION/NORMAL VEC3, TEXCOORD_0 VEC2, COLOR_0 VEC3 or VEC4, joints and weights VEC4, indices SCALAR);
  • a count, byteOffset or byteStride that is a fraction, a string or a bool is an error. Main ran int() on them, so "3" read as 3 and an offset of 1.5 read from byte 1.

The change is one new function ahead of _read_glb_accessor, one call and a try around the JSON decode. It stays out of the lines #5764 (main's handler, output paths) and #5824 (embedded PNGs) touch; git merge-tree against both heads is clean.

Tested

Windows 11, Python 3.14.4, head 7f17f7f6e. Synthetic GLBs built in the test; no game files, no GPU.

  • python -I tests/test_ped_assemble_malformed_glb.py: 8 tests OK (48 malformed documents, two short BIN chunks, two unparsable JSON chunks, three real CLI runs, the name and whole-float cases).
  • The same test with main's tools/ped_assemble.py: 57 failing subcases; the two "still reads" tests pass on both trees.
  • python -I tests/test_ped_assemble.py: 14 OK. tests/test_ci_registration.py: 14 OK. tests/test_runner_calls_all_tests.py: 3 OK. tests/test_text_write_line_endings.py: 3 OK. tests/test_docs_repo_paths.py: 3 OK.
  • python -m compileall -q make_game.py tools tests and git diff --check: clean.

Not tested: GLBs exported from the game (I have no copy), and other writers' GLBs beyond the project's own.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not a translator change)

🤖 Generated with Claude Code

…ceback

read_glb_parts walked the GLB document without checking it, so a material or
pbrMetallicRoughness that is not an object (AttributeError), an accessor past
the BIN chunk (struct.error), an index out of range or a JSON chunk that does
not parse ended the CLI in a Python traceback.

_check_glb_document now checks, before the part loop, what the reader
dereferences: the tables it indexes, the accessors its primitives name (type,
and that their bytes are inside the BIN chunk) and the material fields it
converts. Inputs the reader tolerated stay tolerated.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kaiffeetasse

Copy link
Copy Markdown

Checked head d8fb362c on Linux with Python 3.14.7 and 3.12.3, hand-built synthetic GLBs only.

What ran

  • python -I tests/test_ped_assemble_malformed_glb.py → 6 tests OK (the 42 MALFORMED documents, 2 short BIN chunks, 2 unparsable JSON chunks, 3 CLI runs), on both interpreters.
  • Negative control, same test file with main's tool (git checkout main -- tools/ped_assemble.py) → FAILED (failures=10, errors=39), i.e. 49 subcases red on 561b65a8. The red/green half is real.
  • tests/test_ped_assemble.py 14 OK, tests/test_ci_registration.py 14 OK, tests/test_runner_calls_all_tests.py 3 OK.

One malformed document still tracebacks on this head

A node whose name is not a string is never looked at by _check_glb_document, and MeshPart.__post_init__ → classify_part_role calls os.path.basename(name):

$ python -I tools/ped_assemble.py assemble name5.glb -o out.glb --source-space y-up   # nodes[0].name = 5
  File ".../tools/ped_assemble.py", line 291, in classify_part_role
    base = os.path.splitext(os.path.basename(name))[0].strip().lower()
TypeError: expected str, bytes or os.PathLike object, not int
exit=1

Also with "name": 3.5, true, or a non-empty list ([] is falsy, so it falls back to the mesh name and reads), and with meshes[0].name = 5 when the node has no name — same exit 1. Suggested fix: in the existing node/mesh loops of _check_glb_document, reject name when present and not a str ({path}: malformed GLB: nodes[i].name must be a string), or str() it where pname is built. This is pre-existing on main, not introduced here, but it is the class the PR closes.

Three inputs main reads fine now exit 2

Main's reader converts with int() (count, byteOffset, byteStride), so on 561b65a8 a document with "count": 3.0, "byteOffset": 0.0 or "byteStride": 12.0 returned a part; on this head each is ERROR: … malformed GLB: … and exit 2 (measured by calling read_glb_parts from both trees on the same bytes). glTF asks for integers, so the error is spec-correct, but the body says "What the reader tolerated stays tolerated, with a test" — either narrow that sentence or let the check accept a float where the reader runs int().

Coverage probe

I mutated the valid document through 403 (path, value) combinations (accessor/table/primitive/material/node fields × None, 0, -1, true, "x", [], {}, 3.5, 1<<40, …) and called the head's read_glb_parts: every case is either a PedAssembleError or reads, except the name ones above. Skin handling (_extract_glb_skin_joint_names) still raises its own PedAssembleError, which the new check leaves alone.

AI-assisted: yes.

…read as before

Review of ItsNotRexed#5999 (kaiffeetasse):

- A node name that is not a string (5, 3.5, true, a non-empty list), or the
  mesh's when the node has none, reached classify_part_role and raised
  TypeError. _check_glb_document now refuses it where the reader would use
  it; a falsy name still falls back, and a mesh name the node overrides is
  left alone.
- count, byteOffset and byteStride go through int() in the reader, so 3.0
  read as 3 on main. The check took only ints and turned those into errors;
  it now takes whole floats too. Fractions, strings and bools stay errors.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@enzo-billis

Copy link
Copy Markdown
Contributor Author

Thanks, both points were right. Fixed in 7f17f7f.

  1. Names. Reproduced: nodes[0].name = 5, 3.5, true or a non-empty list, and meshes[0].name = 5 with no node name or no nodes, all raised TypeError in classify_part_role. _check_glb_document now refuses a non-text name where the reader would use it (nodes[i].name must be a string, got 5). A falsy node name still falls back to the mesh's, and a non-text mesh name that the node's name overrides is left alone, since both read on main.
  2. Whole floats. count, byteOffset and byteStride written as 3.0 / 0.0 / 12.0 read again, as on main. Fractions, strings and bools stay errors; main ran int() on those too ("3" read as 3, an offset of 1.5 read from byte 1), so that part is a deliberate tightening and the description now says so instead of claiming everything tolerated stays tolerated.

python -I tests/test_ped_assemble_malformed_glb.py: 8 OK on the new head, 57 failing subcases with main's tool; tests/test_ped_assemble.py 14 OK.

AI-assisted.

@enzo-billis

Copy link
Copy Markdown
Contributor Author

Closing: this is on main. #6208 was built on these two commits ("Depends on: #5999") and its squash merge 9a5d18a carries them: _check_glb_document and tests/test_ped_assemble_malformed_glb.py are on main 1cc6e3c, with the one "accessor without bufferView" case adapted for sparse accessors, and the test passes there (8 OK). Nothing is left to rebase.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants