saves: reject JSON nested deeper than 512 levels explicitly #8
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!8
Loading…
Reference in a new issue
No description provided.
Delete branch "saves-json-nesting-limit"
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: none — the original project's coordination issue was lost with its repository, and this repository has no such issue yet. No open pull request touches
tools/saves.py.Depends on: none.
What and why
Python 3.14's
jsondecoder is iterative, so a deeply nested document no longer raisesRecursionError.parse_jsavaccepted a body nesting 100,000 levels,infoprintedJSAV (200112 bytes),verifysaidOK, andextractdied with a 1,027-line traceback and exit 1 (json.dumpis still recursive).tests/test_saves.pyalready expects a validation error here and its comment notes that the C decoder's limit differs by platform, so the tool should not depend on the interpreter's.The tool now counts nesting itself (
JSON_NESTING_LIMIT = 512, brackets inside strings ignored) inparse_jsav, inverify's per-block check and when it reads a packed index. 512 is far above real saves (a few levels) and below the depth at which Python's recursive encoder fails around the default recursion limit.docs/saves.mdrecords the rule.Tested
main@30daa6958, macOS 15 arm64 (Apple M3 Pro), CPython 3.15.2, CPU only, no game files. Synthetic JSAV with one block{"nested":+ 100,000[+0+ 100,000]+}:main@30daa6958saves.py infoERROR: JSAV body is not valid UTF-8 JSON: nesting exceeds 512 levelssaves.py verifyOKsaves.py extractpython -I tests/test_saves.py→ 70 tests OK (skipped=1) with the fix,FAILED (failures=7)before it on this Python. Alltests/test_docs_*.pypass,compileallclean,check_no_game_data.pyclean.On Python 3.12 (CI) the depth guard is additional and the suite is green there before and after. Not run: Windows, any GPU test, the translator suite.
AI-assisted: yes.
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)