Repository navigation
saves: pack refuses an --out that names the index or a block file it reads (EGEN-SAVES-PACK-OUT) - #6823
Conversation
pack_from_dir reads src/index.json and each block file the index lists. A destination that resolves to one of them replaced the source after the read, so pack out out/index.json rewrote the extracted index. Check every read path with report_paths.same_report_path, which covers case and hard links, and name the file in the error.
A synthetic JSAV extract, then saves.pack with --out spelled as the index and as the first block: both are refused with a ValueError naming the file, and the bytes of the source are unchanged.
Run saves.py pack <dir> <dir>/index.json as a child process: exit 2, one ERROR line, no traceback, and the index is still the extracted JSON.
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Independent review on Windows 11 x64, Python 3.12.
- Red-first verification on Windows: On parent revision
main(1cc6e3c12), runningsaves.py pack <extracted> <extracted>/index.jsonor.../blocks/000_code_*.jsonsilently overwrites the source file being packed. On this head,same_report_pathdetects the collision before any staging files are written, raisingValueErrorand exiting 2 with anERROR:diagnostic while preserving the source. python -I -m compileall -q tools/saves.py tests/test_saves.py(exit 0)python -I tests/test_saves.py(67/67 passed, includingtest_pack_refuses_an_out_that_names_a_source_fileandtest_cli_pack_refuses_an_out_that_names_the_index)python -I tools/saves.py --help(exit 0)python -I scripts/check_no_game_data.py(exit 0)git diff --checkclean (0).
LGTM. AI-assisted; synthetic tests only, no game files or GPU used.
shayderrr
left a comment
There was a problem hiding this comment.
Summary
tools/saves.py::pack_from_dir(src, refuse=None) checks each file it reads against the resolved destination with same_report_path before creating a staging file, and pack passes --out through; PackIndexValidationTest covers both the index and a block file.
Why merge
Stops pack out out/index.json from overwriting the extracted index it just parsed, leaving the source untouched and reporting one ERROR: with exit 2. Narrow overwrite guard with CLI and API tests.
Verdict: Approve
|
Summary Why merge Verdict: Approve |
Item: EGEN-SAVES-PACK-OUT (DeepSeek8)
What changed and why
tools/saves.py pack <extracted dir> <out>readssrc/index.jsonand then every block file the index lists, and only after that writes<out>. Nothing compared--outwith those source files, sopython -I tools/saves.py pack out out/index.jsonreplaced the extracted index with the packed JSAV after reading it, andpack out out/blocks/000_code_*.jsondid the same to a block. On main 1cc6e3c:pack_from_dirnow takes the resolved destination and checks each file it reads withreport_paths.same_report_path(the shared guard: realpath, normcase,samefilefor hard links, the folding-volume probe). A match raises aValueErrornaming the file before the staging temp file is created, so the refused run leaves the source untouched andmain()reports oneERROR:line with exit 2.Test
Added to
tests/test_saves.py, classPackIndexValidationTest(synthetic JSAV built by the test; no game data, no GPU):test_pack_refuses_an_out_that_names_a_source_file—--outspelled asindex.jsonand as the first block file:ValueErrornaming the file, no "invalid JSON" label, source bytes unchanged.test_cli_pack_refuses_an_out_that_names_the_index— child process: exit 2, oneERROR:line, no traceback, index still the extracted JSON.Manual before/after: with a one-block synthetic JSAV extract,
saves.pack(out, out/index.json)rewrote the index (hash changed) on main and raises... pack reads this file, and --out ... would replace iton the branch;saves.pack(out, <tmp>/packed.jsav)still produces bytes identical to the original save.No GPU needed.
Notes
same_path/is_inside_dirversion of it together with console-encoding and extract changes; this PR is only the pack guard and touches onlysaves.pyandtest_saves.py, so it can land independently. saves: pack refuses entry paths outside the extract folder #5107 is about entry paths escaping the extract folder, a different check.pack_from_dirreads (index.jsonplus the entries it validates) rather than everything undersrc:extractoutput may be packed to a sibling name in the same folder, andpackdoes not read that name.source()is used for the index too, with the JSON parse moved out of the guard so a refusal is not reported asinvalid JSON (...); the existing malformed-index tests and their messages are unchanged.AI-assisted.