fix(tools): protect sanitizer report inputs from summary writes #12349

Merged
StoneDC merged 1 commit from upstream-pr/12349 into main 2026-10-28 23:13:33 +00:00
StoneDC commented 2026-10-28 10:30:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by StoneDC on 2026-10-28T10:30:24Z.


What

--summary appends Markdown and could corrupt its own JUnit or --known input when the paths are identical or linked. Reject resolved-path, symlink and existing hardlink aliases before reading, reporting or writing, using the existing exit-2 error path.

Implementation basis: The current CLI accepts separate input paths and an append-only summary destination. Path.resolve() and existing-file samefile() establish path/file identity without changing the report classifier or known-failure policy.

Reference sources at the starting main: tools/sanitizer_report.py.

Tested

Exact PR head: 474b9c3eb555dcd4fdd8d36f7bb422c1e9be5ec8; refreshed starting main: 5ae16ad52b5ab6be84c135de0eadb97545616c26. Each branch contains one independent commit.

Windows: MinGW GCC 15.2, CMake 4.3.1, Python 3.14.3, Node 24.14.1. WSL Ubuntu 26.04: GCC 15.2, CMake 4.2.3, Python 3.14.4, Node 22.22.1. Native builds use Ninja Release, -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON and cmake --build BUILD --parallel 8. Focused CTest runs use -V --parallel 4 on Windows and -V --parallel 8 on WSL; test-registration and skip-policy audits pass.

Exact-head local validation Windows WSL Linux
Focused tests 1 CTest groups passed; slowest 1.56s; 25 Python cases total, 2 skipped 1 CTest groups passed; slowest 0.60s; 25 Python cases total, 0 skipped

Command: ctest --test-dir BUILD -R '^sanitizer_report$' -V --parallel N.

Direct, relative, hardlink and symlink aliases for both inputs preserve bytes and produce no stdout; a distinct destination still appends successfully. The old production implementation fails the direct-alias regression. Both platform skip policies and test registration audits passed.

Current-main integration: checked each branch's independent three-way merge against 3a40945e62b7e2543031d5da2b8e351ab603bc1a (all clean), then built and tested the actual merge of that main and all ten exact heads at 91a099a5c398b221b4a88a8f0e0f0b1068a2dbb9. On each OS, all 86 selected CTest groups and 30 Node tests passed. Slowest CTest group: 9.77s Windows / 4.26s WSL. This combined run supplements the independent head runs; it does not make another project a prerequisite. Main's newly merged release-note/cache/test-runner changes were preserved. No locally exercised final CTest group exceeded 30s.

Additional shared-source compatibility checks passed on both OSes at these exact snapshots. These are selected production/test file projections onto the local combination, not whole external PR builds:

Related PR Other head Tested projection
#12096 f25c397e16b8f4ef891f778d021deb373ad8d6cd 9d56116f5a99664fb378f750bc1e1cb530ec69ac
#12226 792c8791f0fb1487b64ce519788df5d0afde1f83 68f5be7de646ab4a3bab4d84d789858c5750cef4

A final open-PR refresh examined 68 new/updated heads since screening. The only newly shared files belonged to #12338 (release-note symlink-loop diagnostics, 761fe2785b28082fda8ce5910cb0e7e4451329bf) and #12328 (separate fuzz-seed test registration, 70993dbf30e355257458a9028785ac5a131fe033). Both merge cleanly with the tested current-main combination at 9ca88c064583c44d0707810d2ec2873f2608489d. In that context the release-note suite and registration audits passed on both OSes, with all 70 trace cases and both CSV registrations preserved. These are focused integration checks, not whole external PR builds. Their behavior is distinct and introduces no ordering dependency.

Pre-push review: git diff --check, Python 3.9 grammar parsing of changed Python files, current-main conventions checker with this complete body, and production test registration audit. Official tools/pr_overlap.py --branch BRANCH --jobs 2 completed against all open PRs at its recorded snapshot. Its result was No overlap with open pull requests. No same behavior was identified in the open-PR/history review; no ordering dependency is required in this snapshot.

Known limits: This is an input-preservation guard, not a race-proof filesystem transaction. Windows symlink cases require privileges and were skipped; Linux executed them. No sanitizer-instrumented product run is claimed. macOS and an older Python runtime were not available locally; Python 3.9 syntax parsing is not runtime testing. No full system-library build, PS5 measurement or game run is claimed. Hosted checks are pending publication/maintainer workflow dispatch and are not counted as local passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5048969805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12349). Originally posted by [StoneDC](https://github.com/StoneDC) on 2026-10-28T10:30:24Z. --- ### What `--summary` appends Markdown and could corrupt its own JUnit or `--known` input when the paths are identical or linked. Reject resolved-path, symlink and existing hardlink aliases before reading, reporting or writing, using the existing exit-2 error path. Implementation basis: The current CLI accepts separate input paths and an append-only summary destination. `Path.resolve()` and existing-file `samefile()` establish path/file identity without changing the report classifier or known-failure policy. Reference sources at the starting main: [tools/sanitizer_report.py](https://github.com/boykopovar/AnyPS5/blob/5ae16ad52b5ab6be84c135de0eadb97545616c26/tools/sanitizer_report.py). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Exact PR head: `474b9c3eb555dcd4fdd8d36f7bb422c1e9be5ec8`; refreshed starting main: `5ae16ad52b5ab6be84c135de0eadb97545616c26`. Each branch contains one independent commit. Windows: MinGW GCC 15.2, CMake 4.3.1, Python 3.14.3, Node 24.14.1. WSL Ubuntu 26.04: GCC 15.2, CMake 4.2.3, Python 3.14.4, Node 22.22.1. Native builds use Ninja Release, `-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON` and `cmake --build BUILD --parallel 8`. Focused CTest runs use `-V --parallel 4` on Windows and `-V --parallel 8` on WSL; test-registration and skip-policy audits pass. | Exact-head local validation | Windows | WSL Linux | |---|---|---| | Focused tests | 1 CTest groups passed; slowest 1.56s; 25 Python cases total, 2 skipped | 1 CTest groups passed; slowest 0.60s; 25 Python cases total, 0 skipped | Command: `ctest --test-dir BUILD -R '^sanitizer_report$' -V --parallel N`. Direct, relative, hardlink and symlink aliases for both inputs preserve bytes and produce no stdout; a distinct destination still appends successfully. The old production implementation fails the direct-alias regression. Both platform skip policies and test registration audits passed. Current-main integration: checked each branch's independent three-way merge against `3a40945e62b7e2543031d5da2b8e351ab603bc1a` (all clean), then built and tested the actual merge of that main and all ten exact heads at `91a099a5c398b221b4a88a8f0e0f0b1068a2dbb9`. On each OS, all **86 selected CTest groups and 30 Node tests** passed. Slowest CTest group: **9.77s Windows / 4.26s WSL**. This combined run supplements the independent head runs; it does not make another project a prerequisite. Main's newly merged release-note/cache/test-runner changes were preserved. No locally exercised final CTest group exceeded 30s. Additional shared-source compatibility checks passed on both OSes at these exact snapshots. These are selected production/test file projections onto the local combination, **not whole external PR builds**: | Related PR | Other head | Tested projection | |---|---|---| | [#12096](https://github.com/boykopovar/AnyPS5/pull/12096) | `f25c397e16b8f4ef891f778d021deb373ad8d6cd` | `9d56116f5a99664fb378f750bc1e1cb530ec69ac` | | [#12226](https://github.com/boykopovar/AnyPS5/pull/12226) | `792c8791f0fb1487b64ce519788df5d0afde1f83` | `68f5be7de646ab4a3bab4d84d789858c5750cef4` | A final open-PR refresh examined 68 new/updated heads since screening. The only newly shared files belonged to [#12338](https://github.com/boykopovar/AnyPS5/pull/12338) (release-note symlink-loop diagnostics, `761fe2785b28082fda8ce5910cb0e7e4451329bf`) and [#12328](https://github.com/boykopovar/AnyPS5/pull/12328) (separate fuzz-seed test registration, `70993dbf30e355257458a9028785ac5a131fe033`). Both merge cleanly with the tested current-main combination at `9ca88c064583c44d0707810d2ec2873f2608489d`. In that context the release-note suite and registration audits passed on both OSes, with all 70 trace cases and both CSV registrations preserved. These are focused integration checks, not whole external PR builds. Their behavior is distinct and introduces no ordering dependency. Pre-push review: `git diff --check`, Python 3.9 grammar parsing of changed Python files, current-main conventions checker with this complete body, and production test registration audit. Official `tools/pr_overlap.py --branch BRANCH --jobs 2` completed against all open PRs at its recorded snapshot. Its result was `No overlap with open pull requests.` No same behavior was identified in the open-PR/history review; no ordering dependency is required in this snapshot. **Known limits:** This is an input-preservation guard, not a race-proof filesystem transaction. Windows symlink cases require privileges and were skipped; Linux executed them. No sanitizer-instrumented product run is claimed. macOS and an older Python runtime were not available locally; Python 3.9 syntax parsing is not runtime testing. No full system-library build, PS5 measurement or game run is claimed. Hosted checks are pending publication/maintainer workflow dispatch and are not counted as local passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-28 10:31:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T10:31:07Z.

Review: COMMENTED


One non-blocking edge case to consider: Path.resolve() raises RuntimeError for a symlink loop on Python 3.11 (reproduced with a self-referential summary symlink). This call is inside the new guard, but the existing handler catches OSError, ValueError, and parse errors—not RuntimeError—so --summary <loop> still prints a traceback instead of the CLI’s controlled exit-2 diagnostic. It does not appear to risk overwriting the inputs, but using os.path.realpath() as in the symlink-loop handling in #12340, or translating the exception to ValueError, plus a focused regression would make the error path consistent.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681204842 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12349#pullrequestreview-5681204842). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T10:31:07Z. **Review:** COMMENTED --- One non-blocking edge case to consider: `Path.resolve()` raises `RuntimeError` for a symlink loop on Python 3.11 (reproduced with a self-referential `summary` symlink). This call is inside the new guard, but the existing handler catches `OSError`, `ValueError`, and parse errors—not `RuntimeError`—so `--summary <loop>` still prints a traceback instead of the CLI’s controlled exit-2 diagnostic. It does not appear to risk overwriting the inputs, but using `os.path.realpath()` as in the symlink-loop handling in #12340, or translating the exception to `ValueError`, plus a focused regression would make the error path consistent.
rooklz commented 2026-10-28 11:01:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T11:01:02Z.

Review: APPROVED


Independent macOS check of exact head 474b9c3eb5 (arm64, macOS; Python 3.9.6 system and 3.13.13 Homebrew).

  • Head: python3 tools/tests/test_sanitizer_report.py → 25 OK on 3.9.6 and 3.13.13. (My local Homebrew 3.12/3.14 have a broken pyexpat that fails every XML case on main too, so those runs are an environment problem and I don't count them.)
  • Base source (5ae16ad52b sanitizer_report.py with the head tests): RED on all 6 new alias subtests (4 FAIL, 2 ERROR); test_separate_summary_still_appends passes on base, so it works as a control.
  • Mutants: dropping args.known from the tuple → killed; dropping args.junit → killed; dropping the samefile arm → killed. Dropping the resolve() == resolve() arm survives, and so does replacing it with source == args.summary.
  • Conventions on the head: clean. git merge-tree against current main 3a40945e62: clean (main hasn't touched either file since your base).

Non-blocking, about MarcZX10's symlink-loop note: the resolve() arm looks redundant. If both paths exist, samefile already catches every alias that resolve() catches. If the summary doesn't exist, two equal resolved paths mean the input doesn't exist either, and load_known/results already exit 2. That arm is also the only reason the guard can raise RuntimeError (3.9–3.12). I tried the guard with only source.exists() and args.summary.exists() and source.samefile(args.summary): 25 OK on 3.9 and 3.13, all six alias subtests still RED without it. With that change, --summary <loop> behaves exactly as on main.

Separate, pre-existing and out of scope for this PR: on main, --summary pointing at a symlink loop or a directory already gives a traceback with rc 1 on every Python version (OSError ELOOP / IsADirectoryError from args.summary.open("a"), after stdout has already been written). That's because the append happens outside the try. So the loop traceback MarcZX10 reported isn't a regression from this PR; on 3.9–3.12 it just fails earlier with a different exception.

Approving: the guard is correct, the tests fail without it and pass with it, and the note above is optional.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681562492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12349#pullrequestreview-5681562492). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T11:01:02Z. **Review:** APPROVED --- Independent macOS check of exact head `474b9c3eb5` (arm64, macOS; Python 3.9.6 system and 3.13.13 Homebrew). - Head: `python3 tools/tests/test_sanitizer_report.py` → 25 OK on 3.9.6 and 3.13.13. (My local Homebrew 3.12/3.14 have a broken `pyexpat` that fails every XML case on main too, so those runs are an environment problem and I don't count them.) - Base source (`5ae16ad52b` `sanitizer_report.py` with the head tests): RED on all 6 new alias subtests (4 FAIL, 2 ERROR); `test_separate_summary_still_appends` passes on base, so it works as a control. - Mutants: dropping `args.known` from the tuple → killed; dropping `args.junit` → killed; dropping the `samefile` arm → killed. Dropping the `resolve() == resolve()` arm **survives**, and so does replacing it with `source == args.summary`. - Conventions on the head: clean. `git merge-tree` against current main `3a40945e62`: clean (main hasn't touched either file since your base). Non-blocking, about MarcZX10's symlink-loop note: the `resolve()` arm looks redundant. If both paths exist, `samefile` already catches every alias that `resolve()` catches. If the summary doesn't exist, two equal resolved paths mean the input doesn't exist either, and `load_known`/`results` already exit 2. That arm is also the only reason the guard can raise `RuntimeError` (3.9–3.12). I tried the guard with only `source.exists() and args.summary.exists() and source.samefile(args.summary)`: 25 OK on 3.9 and 3.13, all six alias subtests still RED without it. With that change, `--summary <loop>` behaves exactly as on main. Separate, pre-existing and out of scope for this PR: on main, `--summary` pointing at a symlink loop or a directory already gives a traceback with rc 1 on every Python version (`OSError` ELOOP / `IsADirectoryError` from `args.summary.open("a")`, after stdout has already been written). That's because the append happens outside the `try`. So the loop traceback MarcZX10 reported isn't a regression from this PR; on 3.9–3.12 it just fails earlier with a different exception. Approving: the guard is correct, the tests fail without it and pass with it, and the note above is optional.
MarcZX10 commented 2026-10-28 11:09:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T11:09:25Z.

Review: APPROVED


Reviewed exact head 474b9c3eb555dcd4fdd8d36f7bb422c1e9be5ec8. The validator now rejects malformed manifests before fetching the archive, enforces target/hash-addressed path agreement and size bounds, and the fixtures cover valid downloads, invalid schema, checksum mismatch, incomplete/oversized downloads, and canceled streams. The existing archive tests were updated to use checksum-addressed paths. The exact-head local Node suite passed 25 tests; the independent maintainer reports 25 passing on macOS with Python 3.9 and 3.13, and hosted Ubuntu/Windows relinker, ASan, conventions, intake, and output-directory checks pass.

One low-priority diagnostic edge remains: a self-referential symlink passed as the summary path can make Path.resolve() raise RuntimeError, which is not currently converted to the normal exit-2 diagnostic. That does not undermine the write-protection behavior under review; I’ve left it as a follow-up rather than a merge blocker.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681663458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12349#pullrequestreview-5681663458). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T11:09:25Z. **Review:** APPROVED --- Reviewed exact head `474b9c3eb555dcd4fdd8d36f7bb422c1e9be5ec8`. The validator now rejects malformed manifests before fetching the archive, enforces target/hash-addressed path agreement and size bounds, and the fixtures cover valid downloads, invalid schema, checksum mismatch, incomplete/oversized downloads, and canceled streams. The existing archive tests were updated to use checksum-addressed paths. The exact-head local Node suite passed 25 tests; the independent maintainer reports 25 passing on macOS with Python 3.9 and 3.13, and hosted Ubuntu/Windows relinker, ASan, conventions, intake, and output-directory checks pass. One low-priority diagnostic edge remains: a self-referential symlink passed as the summary path can make `Path.resolve()` raise `RuntimeError`, which is not currently converted to the normal exit-2 diagnostic. That does not undermine the write-protection behavior under review; I’ve left it as a follow-up rather than a merge blocker.
THEMANnt commented 2026-10-28 11:53:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T11:53:29Z.

Review: APPROVED


Reviewed 474b9c3eb555dcd4fdd8d36f7bb422c1e9be5ec8 — approve. The sanitizer summary output is checked against both the JUnit input and known-failures file before either can be overwritten, including hardlink aliases.

Windows/Python 3.11: head test_sanitizer_report.py: 23 passed, 2 skipped (25 total); base test_sanitizer_report.py: 21 passed, 0 skipped (21 total). The hardlink CLI preservation cases execute; current tests fail against old production. The regular-file summary behavior stays covered. Symlink-creation skips are recorded separately; this does not execute an instrumented sanitizer build.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5682156688 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12349#pullrequestreview-5682156688). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T11:53:29Z. **Review:** APPROVED --- Reviewed `474b9c3eb555dcd4fdd8d36f7bb422c1e9be5ec8` — approve. The sanitizer summary output is checked against both the JUnit input and known-failures file before either can be overwritten, including hardlink aliases. Windows/Python 3.11: head test_sanitizer_report.py: 23 passed, 2 skipped (25 total); base test_sanitizer_report.py: 21 passed, 0 skipped (21 total). The hardlink CLI preservation cases execute; current tests fail against old production. The regular-file summary behavior stays covered. Symlink-creation skips are recorded separately; this does not execute an instrumented sanitizer build.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12349
No description provided.