Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
StoneDC:fix/sanitizer-summary-input-aliases
Oct 28, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
StoneDC:fix/sanitizer-summary-input-aliases

Conversation

@StoneDC

@StoneDC StoneDC commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

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

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@MarcZX10

Copy link
Copy Markdown
Contributor

I fetched the exact PR head (474b9c3eb555) and ran python3 tools/tests/test_sanitizer_report.py with Python 3.11.2: 25 tests passed, including the added direct-path, hardlink, symlink and non-alias append cases. My earlier comment notes one non-blocking symlink-loop diagnostic edge; hosted relinker and conventions checks are still pending.

@rooklz rooklz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026

@THEMANnt THEMANnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 12437 tools/sanitizer_report.py L123

@oneandonlydean
oneandonlydean merged commit 27cf3df into boykopovar:main Oct 28, 2026
13 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.

5 participants