Skip to content

saves: pack refuses an --out that names the index or a block file it reads (EGEN-SAVES-PACK-OUT) - #6823

Merged
shayderrr merged 3 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/8-saves-pack-out
Nov 23, 2026
Merged

shayderrr merged 3 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/8-saves-pack-out

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Item: EGEN-SAVES-PACK-OUT (DeepSeek8)

What changed and why

tools/saves.py pack <extracted dir> <out> reads src/index.json and then every block file the index lists, and only after that writes <out>. Nothing compared --out with those source files, so python -I tools/saves.py pack out out/index.json replaced the extracted index with the packed JSAV after reading it, and pack out out/blocks/000_code_*.json did the same to a block. On main 1cc6e3c:

wrote C:\...\x\index.json (128 bytes)
index rewritten: True

pack_from_dir now takes the resolved destination and checks each file it reads with report_paths.same_report_path (the shared guard: realpath, normcase, samefile for hard links, the folding-volume probe). A match raises a ValueError naming the file before the staging temp file is created, so the refused run leaves the source untouched and main() reports one ERROR: line with exit 2.

Test

Added to tests/test_saves.py, class PackIndexValidationTest (synthetic JSAV built by the test; no game data, no GPU):

  • test_pack_refuses_an_out_that_names_a_source_file — --out spelled as index.json and as the first block file: ValueError naming the file, no "invalid JSON" label, source bytes unchanged.
  • test_cli_pack_refuses_an_out_that_names_the_index — child process: exit 2, one ERROR: line, no traceback, index still the extracted JSON.
python -I tests/test_saves.py
before (main 1cc6e3c12, the new test file run against the main tools):
  FAILED (failures=2)   # both subtests reached saves.pack, which printed "wrote ...index.json"
after:
  Ran 67 tests in 4.181s
  OK (skipped=1)
python -m compileall -q tools/saves.py tests/test_saves.py   # pass

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 it on the branch; saves.pack(out, <tmp>/packed.jsav) still produces bytes identical to the original save.

No GPU needed.

Notes

  • This is the standalone overwrite guard. The open, conflicting saves: survive redirected console on Windows and validate pack/extract destinations #1438 carries a same_path/is_inside_dir version of it together with console-encoding and extract changes; this PR is only the pack guard and touches only saves.py and test_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.
  • The check covers exactly the files pack_from_dir reads (index.json plus the entries it validates) rather than everything under src: extract output may be packed to a sibling name in the same folder, and pack does 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 as invalid JSON (...); the existing malformed-index tests and their messages are unchanged.

AI-assisted.

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 LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review on Windows 11 x64, Python 3.12.

  • Red-first verification on Windows: On parent revision main (1cc6e3c12), running saves.py pack <extracted> <extracted>/index.json or .../blocks/000_code_*.json silently overwrites the source file being packed. On this head, same_report_path detects the collision before any staging files are written, raising ValueError and exiting 2 with an ERROR: 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, including test_pack_refuses_an_out_that_names_a_source_file and test_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 --check clean (0).

LGTM. AI-assisted; synthetic tests only, no game files or GPU used.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@shayderrr

Copy link
Copy Markdown
Collaborator

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

@shayderrr
shayderrr merged commit 0143398 into ItsNotRexed:main Nov 23, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants