mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:50:52 +01:00
[PR #1463] psin_data: break cyclic array/map recursion, bound align_log2, and validate block_table/collect bounds (PSIN-DATA-RECURSION-AND-BOUNDS) #1493
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1493
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1463
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/psin-data-recursion-and-bounds📝 Commits (1)
ed37d34psin_data: break cyclic array/map recursion, bound align_log2, and validate block_table/collect bounds📊 Changes
2 files changed (+130 additions, -5 deletions)
View changed files
📝
tests/test_psin_data.py(+81 -0)📝
tools/psin_data.py(+49 -5)📄 Description
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()).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.