pe: harden call_evidence CLI input/output guards and atomic writes #2658

Merged
Ammmae0x merged 4 commits from upstream-pr/2666 into main 2026-11-26 02:55:27 +00:00
Ammmae0x commented 2026-11-26 01:34:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:34:21Z.


Change

Harden tools/call_evidence.py CLI path validation and output writing, and add a pure-Python synthetic PE32+ CLI test suite (tests/call_evidence_cli_check.py) registered in CMakeLists.txt as pe_call_evidence_cli_check (TIMEOUT 60).

  • Add _write_atomic(path, content) writing UTF-8 text to a sibling temporary file and atomically replacing the target, unlinking the temporary file on any exception so failed writes leave zero .tmp files.
  • Add _validate_output(output) rejecting symlink, directory, non-regular-file, and non-directory-parent output paths upfront, along with output.is_relative_to(root) / output.resolve().is_relative_to(root) overlap checks.
  • Add _validate_inputs(root, parser) verifying each expected DLL in root is a regular, non-symlink, readable file before invoking inspect().
  • Annotate main(argv: Sequence[str] | None = None) -> int and update __main__ to raise SystemExit(main()) with zero raw tracebacks.

Verification

  • Commit: b0e5efb4 (based on upstream/main 31bcd9ad)
  • out\pe-env\Scripts\python.exe -B tests\call_evidence_cli_check.py -> Ran 9 tests in 1.344s / OK (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\call_evidence_check.py -> Ran 6 tests in 0.636s / OK (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py -> form coverage checks passed (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 510 links. (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> Self-test passed. Checked 1893 tracked source, script and build/CI files: no bidirectional controls. (exit 0)
  • Spot-mutation gate: 3/3 mutations killed (_validate_output directory check, _validate_inputs symlink check, _write_atomic temp unlink cleanup).
  • Negative controls: missing/non-directory/partial input dirs, directory/unreadable/live-symlink/dangling-symlink DLLs, output inside root / existing directory / file parent / file ancestor / live & dangling symlink, corrupt PE & mocked dumpbin failures, mocked Path.replace & NamedTemporaryFile failures leaving zero .tmp files and preserving prior output, and Python 3.14-safe argparse checks.

Evidence and follow-up

All PE32+ binaries and DXBC containers in tests/call_evidence_cli_check.py are synthetically generated in pure Python under the repository MIT license, with mocked dumpbin disassembly; no game files or external binaries are included. Existing tests/call_evidence_check.py and output JSON schema are preserved.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6617489561 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2666). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T01:34:21Z. --- ## Change Harden `tools/call_evidence.py` CLI path validation and output writing, and add a pure-Python synthetic PE32+ CLI test suite (`tests/call_evidence_cli_check.py`) registered in `CMakeLists.txt` as `pe_call_evidence_cli_check` (`TIMEOUT 60`). - Add `_write_atomic(path, content)` writing UTF-8 text to a sibling temporary file and atomically replacing the target, unlinking the temporary file on any exception so failed writes leave zero `.tmp` files. - Add `_validate_output(output)` rejecting symlink, directory, non-regular-file, and non-directory-parent output paths upfront, along with `output.is_relative_to(root)` / `output.resolve().is_relative_to(root)` overlap checks. - Add `_validate_inputs(root, parser)` verifying each expected DLL in `root` is a regular, non-symlink, readable file before invoking `inspect()`. - Annotate `main(argv: Sequence[str] | None = None) -> int` and update `__main__` to `raise SystemExit(main())` with zero raw tracebacks. ## Verification - Commit: `b0e5efb4` (based on `upstream/main` `31bcd9ad`) - `out\pe-env\Scripts\python.exe -B tests\call_evidence_cli_check.py` -> `Ran 9 tests in 1.344s / OK` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\call_evidence_check.py` -> `Ran 6 tests in 0.636s / OK` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py` -> `form coverage checks passed` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 510 links.` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> `Self-test passed. Checked 1893 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) - Spot-mutation gate: 3/3 mutations killed (`_validate_output` directory check, `_validate_inputs` symlink check, `_write_atomic` temp unlink cleanup). - Negative controls: missing/non-directory/partial input dirs, directory/unreadable/live-symlink/dangling-symlink DLLs, output inside root / existing directory / file parent / file ancestor / live & dangling symlink, corrupt PE & mocked `dumpbin` failures, mocked `Path.replace` & `NamedTemporaryFile` failures leaving zero `.tmp` files and preserving prior output, and Python 3.14-safe argparse checks. ## Evidence and follow-up All PE32+ binaries and DXBC containers in `tests/call_evidence_cli_check.py` are synthetically generated in pure Python under the repository MIT license, with mocked `dumpbin` disassembly; no game files or external binaries are included. Existing `tests/call_evidence_check.py` and output JSON schema are preserved. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
tedin7 commented 2026-11-26 02:05:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T01:36:59Z.

Review: COMMENTED


Review of head b0e5efb4 (comment only).

Checked:

  • tools/call_evidence.py: new _validate_inputs, _validate_output, _write_atomic; the report is now written via a sibling temp file and replaced atomically, and the temp file is removed on any failure. main() returns an int and __main__ uses raise SystemExit(main()). Output schema is unchanged.
  • No other open or merged PR adds atomic writes or output-path validation here (#1921 and #131 are different slices; #2500 was closed).
  • CMake registration pe_call_evidence_cli_check sits next to call_evidence_check, same Python guard.
  • The tests are fully synthetic PE32+ in pure Python, with mocked disassembly. No game files.

Commands run locally (Linux, Python venv with pefile):

  • python3 -B tests/call_evidence_cli_check.py -> Ran 9 tests, OK
  • python3 -B tests/call_evidence_check.py -> Ran 6 tests, OK
  • python3 tests/docs_links_check.py -> passed
  • python3 tests/bidi_controls_check.py -> passed
  • git diff --check origin/main...HEAD -> clean
  • Mutations, each made the new suite fail (1 failure each), then reverted: output-directory check disabled; temp-file unlink replaced by pass; input symlink check disabled.

No blocking findings. Windows build/test results are tracked separately.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067387514 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2666#pullrequestreview-6067387514). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T01:36:59Z. **Review:** COMMENTED --- Review of head b0e5efb4 (comment only). Checked: - `tools/call_evidence.py`: new `_validate_inputs`, `_validate_output`, `_write_atomic`; the report is now written via a sibling temp file and replaced atomically, and the temp file is removed on any failure. `main()` returns an int and `__main__` uses `raise SystemExit(main())`. Output schema is unchanged. - No other open or merged PR adds atomic writes or output-path validation here (#1921 and #131 are different slices; #2500 was closed). - CMake registration `pe_call_evidence_cli_check` sits next to `call_evidence_check`, same Python guard. - The tests are fully synthetic PE32+ in pure Python, with mocked disassembly. No game files. Commands run locally (Linux, Python venv with pefile): - `python3 -B tests/call_evidence_cli_check.py` -> Ran 9 tests, OK - `python3 -B tests/call_evidence_check.py` -> Ran 6 tests, OK - `python3 tests/docs_links_check.py` -> passed - `python3 tests/bidi_controls_check.py` -> passed - `git diff --check origin/main...HEAD` -> clean - Mutations, each made the new suite fail (1 failure each), then reverted: output-directory check disabled; temp-file unlink replaced by `pass`; input symlink check disabled. No blocking findings. Windows build/test results are tracked separately. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 03:03:05 +00:00
tedin7 commented 2026-11-26 03:03:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:13:41Z.

Review: COMMENTED


Review of head bf589769 (merge of main into the PR; the PR's own change is the same as b0e5efb4).

What I checked:

  • tools/call_evidence.py: symlink/dir/non-regular/readability guards on inputs and output, output-overlap check before inspect(), atomic write with temp cleanup on any exception, struct.error now reported as a clean exit 1. parser.error stays outside the caught exception types, so exit 2 is preserved. Logic looks correct.
  • No overlap with merged #1921 (it has no atomic write or symlink guards); #2500 is closed.
  • CMakeLists.txt: pe_call_evidence_cli_check is registered next to call_evidence_check, TIMEOUT 60.

Commands run (Linux, worktree at the exact head, pefile in a venv):

  • python -B tests/call_evidence_cli_check.py -> Ran 9 tests, OK
  • python -B tests/call_evidence_check.py -> Ran 6 tests, OK
  • python3 tests/docs_links_check.py -> passed
  • python3 tests/bidi_controls_check.py -> passed
  • git diff --check origin/main...HEAD -> clean
  • Mutations, each makes the new suite FAIL (restored after): input symlink check disabled; temp unlink on failure disabled; output directory check disabled.

Verdict: sound. Python-only change; Windows receipt still needed before merge.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067645702 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2666#pullrequestreview-6067645702). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:13:41Z. **Review:** COMMENTED --- Review of head bf589769 (merge of main into the PR; the PR's own change is the same as b0e5efb4). What I checked: - `tools/call_evidence.py`: symlink/dir/non-regular/readability guards on inputs and output, output-overlap check before `inspect()`, atomic write with temp cleanup on any exception, `struct.error` now reported as a clean exit 1. `parser.error` stays outside the caught exception types, so exit 2 is preserved. Logic looks correct. - No overlap with merged #1921 (it has no atomic write or symlink guards); #2500 is closed. - `CMakeLists.txt`: `pe_call_evidence_cli_check` is registered next to `call_evidence_check`, TIMEOUT 60. Commands run (Linux, worktree at the exact head, pefile in a venv): - `python -B tests/call_evidence_cli_check.py` -> Ran 9 tests, OK - `python -B tests/call_evidence_check.py` -> Ran 6 tests, OK - `python3 tests/docs_links_check.py` -> passed - `python3 tests/bidi_controls_check.py` -> passed - `git diff --check origin/main...HEAD` -> clean - Mutations, each makes the new suite FAIL (restored after): input symlink check disabled; temp unlink on failure disabled; output directory check disabled. Verdict: sound. Python-only change; Windows receipt still needed before merge. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 03:03:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:55:17Z.


Win2025 WARP receipt for head 8a4d5e83 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 8a4d5e83b2001fdade3fd36ab52d316ee61ff6a9:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 478.44s (configure 3.96s)
    • Test (ctest --preset dev -R 'pe_call_evidence' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (4.03s: pe_call_evidence_cli_check 3.82s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 452.99s (configure 3.29s)
    • Test (ctest --preset release -R 'pe_call_evidence' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (3.43s: pe_call_evidence_cli_check 3.22s)
  • Windows Python checks: tests/dxcontainer_part_offsets_check.py ok (0.7s)
  • sccache: 2565/2897 hits; wall 954.2s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181235872 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2666#issuecomment-7181235872). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:55:17Z. --- Win2025 WARP receipt for head 8a4d5e83 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `8a4d5e83b2001fdade3fd36ab52d316ee61ff6a9`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `478.44s` (configure `3.96s`) - Test (`ctest --preset dev -R 'pe_call_evidence' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`4.03s`: `pe_call_evidence_cli_check` `3.82s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `452.99s` (configure `3.29s`) - Test (`ctest --preset release -R 'pe_call_evidence' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`3.43s`: `pe_call_evidence_cli_check` `3.22s`) - **Windows Python checks**: `tests/dxcontainer_part_offsets_check.py` ok (`0.7s`) - `sccache`: 2565/2897 hits; wall `954.2s` AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!2658
No description provided.