Repository navigation
saves: validate editable pack indexes before rebuilding - #2779
Conversation
|
Code read of AI-assisted review (Claude Code). |
|
Keeping the existing local-file reference behavior in this PR: it validates the editable index's consumed fields, without introducing a self-contained-folder policy. Both relative |
|
Tested on Linux (WSL2 Ubuntu, Python 3.12) and native Windows 11 (Python 3.13.1), CPU only: pass. Merges cleanly with main. tests/test_saves.py: Linux 38 tests OK, Windows 38 tests OK, 0 skips on both. Negative control (tools/saves.py restored to main, Linux): fails (10 failures, 39 errors), so the tests exercise the new validation. Trial merge with #2688 (also edits tools/saves.py and tests/test_saves.py) is clean and the combined test file passes on Linux (50 tests, 1 skip from the other PR). |
Kam471
left a comment
There was a problem hiding this comment.
Verified on the PR head: python -I tests/test_saves.py -> 38 tests OK; test_saves_import_args.py -> 1 OK; test_save_keys.py -> 24 OK. On base 4947579 the same suite fails 10 + 39 errors (the expected tracebacks and accepted bools), so the validation is exercised. Both invalid-input tests leave existing output byte-identical. Synthetic data and TemporaryDirectory only; no game data or absolute paths.
Non-blocking: an index nested ~50k arrays deep still raises RecursionError from json.loads, which prints a traceback instead of the clean exit-2 path; catching it with ValueError would make that guarantee total.
|
Tested on Windows 11 / Python 3.13.0, merged onto current Approve. AI-assisted review, no game files. |
|
Addressed the malformed deeply nested JSON finding in 89dc62f. The JSON decoder's RecursionError now follows the existing filename-specific validation-error path. Added parser and subprocess CLI regressions at depth 6000: exit 2, no traceback, previous destination bytes unchanged. Both tests failed before the correction. Windows CPython 3.12.10: 40 save tests, 1 import-argument test and 24 save-key tests passed; compilation and diff checks passed. Synthetic data only; AI-assisted. |
|
Portability follow-up in acffe1b: the Linux review of #3565 showed CPython 3.12 can accept 6,000 nested arrays, so I raised both matching pack-index fixtures here to 100,000 (the reviewer's Linux probe overflowed there). This prevents the test from accidentally reaching the different root-shape validation path. Production handling is unchanged. Windows CPython 3.12.10: 40 save tests pass; combined save branches 60 tests pass with 3 existing platform skips. Native Linux recheck remains pending. AI-assisted. |
An edited or damaged save-pack
index.jsoncould raise uncaught TypeError/KeyError and print a traceback. For example, a nullheaderexited 1 instead of using the CLI's clear input-error path. Validate the index/header/entry shapes and the fields consumed by the packer before reading blocks or rebuilding; errors now name the index and invalid field and return exit code 2.Validation covers uint32 version/flag/hash fields and a code-block count within the entry count. Extra metadata, existing hexadecimal spellings and a minimal empty index remain accepted. Existing output is untouched on invalid input.
Claim: #2516 (comment) (new editable-index validation item). Independent of #1438's destination checks, #2603's binary-container bounds and #2688's atomic publication/link policy; no dependency on them.
Tested on Windows 11 Pro, CPython 3.12.10, synthetic files only:
49475796produced 8 failures/39 errors, including CLI tracebacks and accepted boolean fields.python -W error::ResourceWarning -I tests/test_saves.py -q: 38 passed. New coverage includes 43 malformed structural/type/range variants, four CLI cases, JSON syntax/encoding diagnostics, output preservation and valid byte-exact/empty-index round trips.test_saves_import_args.py: 1 passed;test_save_keys.py: 24 passed.No game files, GPU/driver validation or C++ runtime changes. AI-assisted with Codex.
Review correction: excessive JSON nesting now produces the same filename-specific validation error (CLI exit 2, no traceback) and preserves an existing output. Two depth-100000 regression tests failed before the fix. Updated Windows CPython 3.12.10 validation: 40 save, 1 import-argument and 24 save-key tests passed; compilation/diff checks passed. AI-assisted.
Portability correction: Linux CPython 3.12 accepts 6,000 nested arrays, as the reviewer reproduced. Both regression fixtures now use 100,000 levels, which exceeded the decoder limit in the reviewer's Linux probe and also passes the Windows error-path checks. Windows CPython 3.12.10: JSAV branch 50 tests (1 POSIX skip), pack-index branch 40 tests, and the combined save branches 60 tests (3 platform skips), all otherwise passing. A native Linux recheck of the updated fixtures is pending. AI-assisted.