Skip to content

analyze_4240_full: --json never overwrites an input archive - #2040

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
XFlawless1:fix/analyze-4240-json-guard
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
XFlawless1:fix/analyze-4240-json-guard

Conversation

@XFlawless1

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new BUILD item (claim). Follow-up of #1410, which left this tool out because #1399 (now merged) was editing the same lines.

What and why

tools/analyze_4240_full.py writes --json after it has read every archive. As a result:

  • A --json that named one of the inputs replaced that archive with the report. This includes another spelling of the same path and a hard link to it. The input is the user's own game archive.
  • A folder given as --json ended the whole scan with a traceback (PermissionError / IsADirectoryError). So did any other failed write.

Now:

  • Before the scan, a --json that is a folder, or that is the same file as any input, is refused with one ERROR: line and exit 2. Nothing is read. Same-file detection uses same_output_path(): realpath + normcase, then os.path.samefile, as in vertex_types.py and instance_lists.py (vertex_types, instance_lists: --json can't overwrite an input archive #1385).
  • A write that still fails, for example when the parent is a file, is one ERROR: cannot write <path>: <reason> line with exit 2.

Tested

Windows 11 Pro 10.0.26300, Python 3.12.10, on 4eb6155d:

  • python -I tests/test_analyze_4240_full.py: 14 OK. Five tests are new: the same path and another spelling of it, a later input, a hard link, a folder, and a failed write. Each checks the exit code, the one error line, no traceback, and that the archive bytes are unchanged. All five fail with main's analyze_4240_full.py.
  • python -m compileall -q make_game.py tools tests: clean.

Synthetic archives built in the test only. No game files.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator rule.)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

The report is written after every archive has been read, so a --json that
named one of the inputs (directly, through another spelling or a link)
replaced that archive with the report. A folder for --json, or a failed
write, ended the full scan with a traceback. Both paths are now refused
before the scan with one ERROR line and exit 2, and a failed write is one
"cannot write" line with exit 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@UNYTIX

UNYTIX commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested f8e5d476c897. Command python -B -I tests/test_analyze_4240_full.py -v.

13 passed, 1 skipped (hard links unavailable). With the base tool from 4eb6155, five subtests failed. The head protected the synthetic input and rejected invalid report destinations.

Independent Windows 11 verification, Python 3.15.2. AI-assisted.

@Jadiac5

Jadiac5 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested f8e5d476 on Windows 11, Python 3.11: pass.

  • Ran: python -I tests/test_analyze_4240_full.py, python -m compileall -q make_game.py tools tests,
    python -I make_game.py --help.
  • test_analyze_4240_full: 14 OK (main at 4eb6155d: 9), as the PR says. The rest exit 0.
  • Code read: the checks run before the scan, so a refused path costs nothing, and both refusals and a failed write
    exit 2 with ERROR:. No concerns with the tool.
  • Small: the new tests read results with open(...).read() without closing the file.
  • Not done: no run on real input files, and the hard-link branch of same_output_path (os.path.samefile) was only
    exercised by the PR's own tests.

Baseline for the counts: main at 4eb6155d, same machine. No runtime/ change in this PR, so no runtime build. AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit d182205 into ItsNotRexed:main Nov 22, 2026
10 of 11 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.

4 participants