Repository navigation
ped_assemble: a malformed GLB is one ERROR line and exit 2, not a traceback - #5999
enzo-billis wants to merge 2 commits into
Conversation
…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>
|
Checked head What ran
One malformed document still tracebacks on this head A node whose Also with Three inputs main reads fine now exit 2 Main's reader converts with Coverage probe I mutated the valid document through 403 (path, value) combinations (accessor/table/primitive/material/node fields × 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>
|
Thanks, both points were right. Fixed in 7f17f7f.
AI-assisted. |
|
Closing: this is on main. #6208 was built on these two commits ("Depends on: #5999") and its squash merge 9a5d18a carries them: AI-assisted. |
Claimed in the coordination issue as: #5934 (comment) (new BUILD item, no ID yet)
What and why
tools/ped_assemble.pyended in a Python traceback on a malformed GLB. On main561b65a83,ped_assemble.py assemble x.glb -o out.glb:AttributeError: 'int' object has no attribute 'get'pbrMetallicRoughnessthat is not an objectAttributeError: 'list' object has no attribute 'get'struct.error: unpack_from requires a buffer of at least 62 bytes ...TypeError: expected str, bytes or os.PathLike object, not intread_glb_partswalked the document without checking it._check_glb_documentnow 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 isERROR: <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 thatfloat()takes, acount/byteOffset/byteStridewritten as a whole float (3.0, which the reader'sint()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:
translationmust have exactly 3 numbers;POSITION/NORMALVEC3,TEXCOORD_0VEC2,COLOR_0VEC3 or VEC4, joints and weights VEC4, indices SCALAR);count,byteOffsetorbyteStridethat is a fraction, a string or a bool is an error. Main ranint()on them, so"3"read as 3 and an offset of1.5read from byte 1.The change is one new function ahead of
_read_glb_accessor, one call and atryaround the JSON decode. It stays out of the lines #5764 (main's handler, output paths) and #5824 (embedded PNGs) touch;git merge-treeagainst 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).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 testsandgit 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
docs/design.md, with how it was confirmed. (not a translator change)🤖 Generated with Claude Code