psin_data: break cyclic array/map recursion, bound align_log2, and validate block_table/collect bounds (PSIN-DATA-RECURSION-AND-BOUNDS) #1463
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1463
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/psin-data-recursion-and-bounds"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: PSIN-DATA-RECURSION-AND-BOUNDS
Summary
Hardens
tools/psin_data.pyagainst cyclic/damaged PSIN container graphs and extreme schema values:Walker.value,Walker.array,Walker.map):Walker.struct()checkeddepth > MAX_DEPTHandself.seen. Cyclic0x5C/0x52/0x50/0x53/0x54arrays or0x71/0x73/0x75maps recursed forever until crashing with an uncaughtRecursionError(neithermeasure()nor--dumpcatchesRecursionError), and branching self-referential arrays (count >= 2) would hang exponentially even with a depth cap alone.depth > MAX_DEPTHinWalker.value()and tracks active container recursion frames inself._visiting(added on entry, removed infinally), terminating cycles in O(1) (stats["container cycle"]) while preserving normal decoding for non-cyclic DAG sharing (two fields pointing to the same read-only array/map).align_log2inContainer.align_of()/Container.slot():align_log2is au8in LSCH (0..255), so a damaged value like250computed1 << 250(~1.8e75) insideslot(). Caps validalign_log2to0..MAX_ALIGN_LOG2(16, 64 KiB) and treats invalid alignments as undecoded (None).block_table()&collect()bounds:block_table(blob, first)now validates8 <= first <= len(blob)and refuses 16-byte end paddingend > firstthat would read pastfirstinto the first section.collect(src, limit=...)now rejectslimit <= 0and booleanlimitvalues instead of silently treatinglimit=0as unlimited.Testing
arm64), Python 3.14 (CPU-only, synthetic PSIN containers only, no game data)python3 -m compileall -q make_game.py tools tests-> cleanpython3 -I scripts/check_no_game_data.py tools/psin_data.py tests/test_psin_data.py-> cleanpython3 -I tests/test_psin_data.py -v-> 34/34 OK (3 new tests)python3 -I tests/test_psin_index.py-> 33/33 OKpython3 -I tests/test_text_write_line_endings.py-> 3/3 OKpython3 -I tests/test_ci_registration.py-> 16/16 OKtests/test_psin_data.pyon unpatchedupstream/mainb4b7756e8):FAILED (failures=2, errors=1)(reproducing uncaughtRecursionError: maximum recursion depth exceededon cyclic array/map,1809251394333065553493296640760748560207343510400633813116524750123642650624alignment onalign_log2=250, and unvalidatedfirstinblock_table()).Red/green: the PR's tests fail on main 4938673 and pass on head ed37d34e17b7 (Linux, Python 3.13.18).
Targeted batch of 11 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)