rpf9_carve: publish index.json atomically and guard stream outputs aliasing input archive (RPF9-CARVE-ATOMIC-INDEX-AND-INPUT-GUARD) #1760
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1760"
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?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T11:34:56Z.
Claimed in the coordination issue as: RPF9-CARVE-ATOMIC-INDEX-AND-INPUT-GUARD https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161163878
What and why
Hardens
tools/rpf9_carve.pyacross three edge cases:.bin/.bk2outputs aliasing the input archive: Before opening<out>/<offset>.bk2or<out>/<offset>.bin, checksame_report_path(out_file, a.archive)(matching the existingindex.jsoncheck) so an input archive named like a carved output insideout_dircannot be truncated on POSIX or fail with a confusing write error on Windows.index.jsonpublishing with Windows read-only cleanup: Replace directopen(index_path, "w", ...)with_write_index_atomic(writes LF-terminated JSON ending in\nto a temporary file in the destination directory, appliespublished_mode(dest), publishes viareplace_retry, and restores0o600before unlinking on failure so Windows read-only targets do not strand.rpf9_carve-*.tmpfiles or leave truncatedindex.jsonbehind).donein the 2,000-row progress print frombaseinstead ofa.start or 0so progress reflects the scanned data span when--startis omitted.Adds 4 synthetic regression tests in
tests/test_rpf9_carve_errors.py.Tested
Windows 11 x64 (
10.0.26100), Python3.14.7, CPU only, synthetic archives only (no game files). Commit0f83828fa789f7efe2162317e8438d0cfd6e8c82.python -I tests/test_rpf9_carve_errors.py -v:main(bcaa13da) with all 7 tests: 4 failures (new tests fail on.bin/.bk2aliasing, truncatedindex.jsonon mid-write failure, and missing trailing newline);python -I tests/test_rpf9_carve.py -v: 17 tests, OK.python -I tests/test_ci_registration.py: 16 tests, OK.python -I tests/test_text_write_line_endings.py: 3 tests, OK.python -I scripts/check_no_game_data.py tools/rpf9_carve.py tests/test_rpf9_carve_errors.py,python -m compileall -q tools tests,git diff --check: exit0.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)Imported from ubiquitarianism/leonida. Originally posted by ShotTechOp on 2026-11-25T12:26:08Z.
Review: APPROVED
Independent Windows 11 / Python 3.12.10 review of
0f83828fapplied ontoorigin/main(0d80bc5d) — CPU-only, synthetic inputs, no game files.Checks run
origin/main(0d80bc5d): clean.python -I tests/test_rpf9_carve_errors.py -v: 7/7 OK (including the native Windowsos.name == "nt"read-onlyindex.jsonpublish check).tools/rpf9_carve.pytoorigin/mainwith the PR's tests): 4 failures across all 4 new tests (bin/bk2input-archive aliasing, failed write truncating previousindex.jsonto"", and missing trailing newline).python -m compileall -q tools/rpf9_carve.py tests/test_rpf9_carve_errors.py: exit 0.python -I scripts/check_no_game_data.py tools/rpf9_carve.py tests/test_rpf9_carve_errors.py: exit 0.git diff --check origin/main: clean.Code audit
_write_index_atomic()pinsencoding="utf-8", newline="\n", setspublished_mode(dest), publishes viareplace_retry, and restores writable mode (0o600) before unlinking the staging file infinally, avoiding Windows read-only staging leaks on failed replaces..bk2and.binstream outputs withsame_report_path(out_file, a.archive)prevents overwriting an input archive named after its own hex offset, and usingbasein the progress denominator fixes the percentage when--startis omitted.LGTM. AI-assisted (Antigravity).
Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T18:28:32Z.
Reviewed
0f83828: ran tests/test_rpf9_carve_errors.py (7 tests OK on the PR tree; the same file on main fails exactly the four new tests, so they cover the fix - the alias runs there truncate the archive and the tool dies of SIGBUS with no message), plus test_rpf9_carve.py (17) and test_carve_short_system_pages.py (11), OK on both trees, and check_no_game_data.py (clean). A probe on both trees confirms the normal carve stays byte-identical (only the intended trailing newline in index.json differs), and that .bin/.bk2 output aliases of the input archive - direct, symlinked and relative spellings - are refused with the archive intact, where main destroys the input. Windows-only paths were not run. Nothing blocking found.AI-assisted review.
Recommendation: Merge
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:57:53Z.
Red/green: classified READY by cloud-4 (red on main
09c153948, green on head merged with main); head0f83828fa7unchanged since 2026-11-25, before that run.Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main
d48a957bbin GitHub Actions: no new failure.AI-assisted (Claude Code, Claude Opus 5.5)