mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:45:53 +01:00
[PR #8] [MERGED] saves: reject JSON nested deeper than 512 levels explicitly #66
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#66
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/8
Author: @wavehs
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism
Base:
main← Head:saves-json-nesting-limit📝 Commits (1)
20c7188saves: reject JSON nested deeper than 512 levels explicitly📊 Changes
2 files changed (+41 additions, -1 deletions)
View changed files
📝
docs/saves.md(+5 -0)📝
tools/saves.py(+36 -1)📄 Description
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.)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.