Skip to content

rsc8_audio: refuse a report path that is a directory or one of the scanned files - #5608

Open
zzEmmazz wants to merge 1 commit into
ItsNotRexed:mainfrom
zzEmmazz:rsc8-audio-out-never-replaces-an-input
Open

zzEmmazz wants to merge 1 commit into
ItsNotRexed:mainfrom
zzEmmazz:rsc8-audio-out-never-replaces-an-input

Conversation

@zzEmmazz

Copy link
Copy Markdown
Contributor

BUILD (new item), claimed in the coordination issue: #5361 (comment)

Depends on: #4355 (overlaps with it in one place, does not build on it; see the last point of "What and why")

What and why

tools/rsc8_audio.py <source> [out] writes its report to a temporary file and renames it over out when the scan
is done. Before the scan, main() only compared out with the source argument itself. On main 3faac557:

  • With a directory source, an out that names a bank or clip inside that directory was accepted, and the file was
    replaced by the report: python -I tools/rsc8_audio.py <dir> <dir>\a.awc --quiet exits 0 and a.awc (a
    4,900-byte synthetic bank) is the JSON report afterwards. The same for a .rsc8 file, a file in a nested
    folder, a truncated bank, and every other spelling of such a path (sub\..\a.awc, another letter case, a
    trailing dot or space on Windows).
  • An out that is an existing directory was refused only by the final rename, after the whole scan, with the
    operating system's "access is denied" text.

Now both are usage errors (exit 2, one rsc8_audio.py: error: line) before anything is read:

  • main() refuses an out that is an existing directory (output must be a file, not a directory: <out>).
  • scan_dir() takes the report path (out=) and compares it with report_paths.same_report_path against the
    list of files it is about to open, right after listing them and before the first one is read, as
    tools/awc_manifest.py does. The list compared is the list read, so a file cannot be scanned without having
    been checked. The error names the input: output must not overwrite the input file <path>.
  • The source-file comparison uses same_report_path too, in place of a bare os.path.samefile. Its results for
    the cases tried are the same as before (same path, .. spelling, letter case, trailing dot, 8.3 name, hard
    link: all refused on main already).
  • A hard link to a scanned file is refused as well. On main that case did not damage the bank (the rename
    replaces the link's name, not the file's data), so this one is stricter, not a fix.
  • Unchanged: a report inside the scanned directory under a name the scan does not read (report.json,
    report.csv, also in a sub-folder or a folder that does not exist yet) is written, and the next run neither
    refuses it nor counts it as an input, because the scan reads .awc and .rsc8 names only. An out that does
    not exist yet works as before. The tool writes no second file derived from out; the temporary file is
    .rsc8_audio.<random>.part next to out, created exclusively and removed on failure.
  • docs/rsc8_audio.md: one sentence at the export example.
  • Overlap with rsc8_audio: fail on an unlistable sub-folder instead of silently skipping its banks #4355: its hunk in tools/rsc8_audio.py has the def scan_dir(...) line as context and this
    adds a parameter on that line, so the two do not merge automatically. The conflict is one region (its new
    _walk_error function above the def line, the new signature here); keeping both sides resolves it, and its
    os.walk(..., onerror=_walk_error) line and its tests merge without a conflict. Resolved that way in a scratch
    copy, tests/test_rsc8_audio.py runs 42 tests, OK (1 skipped: its chmod test, on Windows), and an unlistable
    sub-folder with an out given ends with exit 2, no traceback and no report. rsc8_audio: the AWC start/end cue records matched into region pairs, record by record (ASSET-320) #5518 applies cleanly on top of
    this (git apply --check, and a three-way merge).

Tested

Windows 11, Python 3.14.0. No GPU is involved. Every input is synthetic (built by the test file's helpers).

  • python -I tests/test_rsc8_audio.py: 40 tests, OK (34 on main plus 6 new). The new ones run the CLI and
    require, for every refused out: exit 2, no traceback, exactly one line after the usage text, nothing on
    stdout, every input byte-identical and no file added or removed in the folder. The folder holds a truncated
    bank that a scan would name on stderr, so the single stderr line also shows that nothing was read.
    • directory source, out = each scanned file (bank, clip, nested bank, truncated bank), sub\..\a.awc,
      sub\deep\..\..\.\a.awc, and on Windows A.AWC, SUB\Deep\NESTED.awc, a.awc. and a.awc (10 cases);
    • out = a hard link to a scanned bank, in another folder under a .json name;
    • out = an existing directory, for a directory source and for a file source (5 cases);
    • file source, out = the same file under another spelling (already refused on main);
    • a report inside the scanned directory (.json, .csv in a nested folder, .json in a new folder), two runs
      each: exit 0 both times, same counts, inputs unchanged, only the three reports added.
  • Negative control: the same test file against main's tools/rsc8_audio.py: 40 tests, 16 failures (10 + 1 + 5
    in the first three groups above); the other two new tests pass there, as they describe behaviour main already has.
  • By hand, with the same synthetic files: an 8.3 short name, a \\?\ path, a \\localhost\C$ path, forward
    slashes, a relative path, a symbolic link to a bank, a path through a directory symbolic link and through a
    junction: all refused, the bank unchanged.
  • python -I tests/test_report_paths.py (15, OK), tests/test_awc_manifest.py (18, OK),
    tests/test_audio_config.py (21, OK), tests/test_text_write_line_endings.py (3, OK),
    tests/test_docs_links.py (6, OK), tests/test_docs_repo_paths.py (2, OK), tests/test_docs_list_items.py
    (2, OK), tests/test_docs_design_rows.py (4, OK), python -m compileall -q make_game.py tools tests,
    python -I make_game.py --help.
  • Cost of the check: a directory of 5,000 four-byte files scans in 0.45 s without out and 1.27 s with one
    (about 0.16 ms per file).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.

Not checked

  • Linux and macOS: the tests were run on Windows only. The letter-case and trailing-dot cases are skipped where
    the volume or the system does not treat the two names as one; a case-insensitive macOS volume was not tried
    (that part is report_paths.py's, which has its own tests).
  • No run on a real archive or a real folder of banks; none is needed for this and none was read.
  • An out that names an existing file the scan does not read is still replaced, whatever it is: for example a
    bank next to a single-file source (rsc8_audio.py a.awc b.awc), or any file with a .awc or .rsc8 name
    outside the scanned folder. The help text says .json or .csv, but any other extension is accepted and
    written as JSON. Left as it is here.
  • Another process that creates or swaps a file between the listing and the final rename.

AI-assisted.

…anned files

With a directory source, an `out` naming a bank or clip inside that
directory was accepted: the scan ran and the report was then renamed over
the file (`rsc8_audio.py <dir> <dir>\a.awc` left a.awc holding the JSON
report). main() only compared `out` with the source argument itself. An
`out` that is an existing directory was refused only by the final rename,
after the whole scan.

Both are now usage errors (exit 2) before anything is read. scan_dir()
takes the report path and compares it, with report_paths.same_report_path,
against the list of files it is about to open, so the files refused are
the files read: other spellings of a path, another letter case on a
volume that ignores case, a trailing dot or space on Windows and a hard
link included. The source-file comparison uses the same function.

A report inside the scanned directory under a name the scan does not read
(.json, .csv) still works and is not counted as an input on the next run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 257dce5 on Windows 11, CPython 3.14.7, CPU only: pass.

I ran the CLI against the synthetic folder from AwcAndArchiveScanTest._scan_folder. With sub/deep/nested.awc as the report destination, parent 3faac55 exits 0 and replaces the bank. The head exits 2 and preserves the original bytes.

With new.json inside the same input folder, both revisions create the report on the first run and update it on the second. Both reports parse as JSON. All four synthetic inputs retain their original bytes after both runs.

py -3.14 -I tests/test_rsc8_audio.py passes all 40 tests. py -3.14 -I tests/test_report_paths.py passes 14 tests and skips one.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 257dce5 merged with main 561b65a on Linux (WSL2) / Python 3.12.16 (-I): pass

tests/test_rsc8_audio.py: 42 run, 42 passed, 0 failed; tests/test_docs_*.py: 11 files, 11 OK (the PR edits docs/rsc8_audio.md). Negative control: with tools/rsc8_audio.py restored from upstream/main the new refusal tests fail (12 failures; e.g. a report path that resolves to a scanned .awc through "sub/deep/../.././a.awc" replaces the bank with the JSON report, which is the bug); restored the PR file and all pass. Not run: a native Windows pass for the case-insensitive path comparison (it goes through the existing report_paths.same_report_path).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 257dce52 on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main 713a949b: pass

  • python -I tests/test_rsc8_audio.py: Ran 54 tests, OK. With only the non-test files reverted to main: FAILED (failures=12), so the new tests exercise the change.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

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