tooling: harden fuzz_cpu CLI path/count guards and atomic writes #2665

Merged
Ammmae0x merged 2 commits from upstream-pr/2673 into main 2026-11-26 03:09:33 +00:00
Ammmae0x commented 2026-11-26 01:44:09 +00:00 (Migrated from github.com)

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


Change

Harden tools/fuzz_cpu.py CLI input/output validation and atomic file writes across emit, translate, and check, and add a pure-Python CLI test suite (tests/fuzz_cpu_cli_check.py) registered in CMakeLists.txt as tooling_fuzz_cpu_cli_check (TIMEOUT 60).

  • Add sibling-temp _write_atomic(path, text) creating missing parent directories, writing UTF-8 with LF newlines, replacing via os.replace, and unlinking temporary files on any failure.
  • Validate count >= 1 upfront in emit(), translate(), and run_check().
  • Validate input PE/DLL files upfront via _validate_input_file() in translate() and run_check() (including optional --mutant).
  • Validate output paths (asm, definition, output) upfront via _validate_output_path() (rejecting symlinks, directories, and non-directory parents) and _validate_distinct_paths() (rejecting identical/overlapping/hardlink-samefile asm vs definition and output vs image paths).
  • Catch (OSError, ValueError, struct.error, KeyError, *_PE_ERRORS) cleanly in main() with concise stderr and exit code 1 (zero raw tracebacks), preserving existing CMake cpu_aot_fuzz* behavior.

Verification

  • Commit: 01e1c5c3 (based on upstream/main 82c70807)
  • out\pe-env\Scripts\python.exe -B tests\fuzz_cpu_cli_check.py -> Ran 9 tests in 8.217s / 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 512 links. (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> Self-test passed. Checked 1899 tracked source, script and build/CI files: no bidirectional controls. (exit 0)
  • Spot-mutation gate: 3/3 mutations killed (_validate_count, _validate_distinct_paths hardlink samefile check, _write_atomic temp unlink cleanup).
  • Negative controls: count <= 0 across all 3 subcommands, missing/directory PE paths in translate and check (including --mutant), corrupt PE in translate, output directory/symlink/file-parent/ancestor-file/collision/hardlink guards, simulated os.replace and staging write failures preserving prior outputs with zero .tmp files, and Python 3.14-safe argparse checks.

Evidence and follow-up

All fixtures in tests/fuzz_cpu_cli_check.py are pure-Python generated temporary inputs and mocked lifter calls under the repository MIT license; no external binaries or game files are used.

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:6617612592 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2673). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T01:44:09Z. --- ## Change Harden `tools/fuzz_cpu.py` CLI input/output validation and atomic file writes across `emit`, `translate`, and `check`, and add a pure-Python CLI test suite (`tests/fuzz_cpu_cli_check.py`) registered in `CMakeLists.txt` as `tooling_fuzz_cpu_cli_check` (`TIMEOUT 60`). - Add sibling-temp `_write_atomic(path, text)` creating missing parent directories, writing UTF-8 with LF newlines, replacing via `os.replace`, and unlinking temporary files on any failure. - Validate `count >= 1` upfront in `emit()`, `translate()`, and `run_check()`. - Validate input PE/DLL files upfront via `_validate_input_file()` in `translate()` and `run_check()` (including optional `--mutant`). - Validate output paths (`asm`, `definition`, `output`) upfront via `_validate_output_path()` (rejecting symlinks, directories, and non-directory parents) and `_validate_distinct_paths()` (rejecting identical/overlapping/hardlink-samefile `asm` vs `definition` and `output` vs `image` paths). - Catch `(OSError, ValueError, struct.error, KeyError, *_PE_ERRORS)` cleanly in `main()` with concise stderr and exit code `1` (zero raw tracebacks), preserving existing CMake `cpu_aot_fuzz*` behavior. ## Verification - Commit: `01e1c5c3` (based on `upstream/main` `82c70807`) - `out\pe-env\Scripts\python.exe -B tests\fuzz_cpu_cli_check.py` -> `Ran 9 tests in 8.217s / 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 512 links.` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> `Self-test passed. Checked 1899 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) - Spot-mutation gate: 3/3 mutations killed (`_validate_count`, `_validate_distinct_paths` hardlink `samefile` check, `_write_atomic` temp unlink cleanup). - Negative controls: `count <= 0` across all 3 subcommands, missing/directory PE paths in `translate` and `check` (including `--mutant`), corrupt PE in `translate`, output directory/symlink/file-parent/ancestor-file/collision/hardlink guards, simulated `os.replace` and staging write failures preserving prior outputs with zero `.tmp` files, and Python 3.14-safe argparse checks. ## Evidence and follow-up All fixtures in `tests/fuzz_cpu_cli_check.py` are pure-Python generated temporary inputs and mocked lifter calls under the repository MIT license; no external binaries or game files are used. ## 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.
upstream-sync closed this pull request 2026-11-26 04:04:14 +00:00
tedin7 commented 2026-11-26 04:04:15 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 36dbe7f3 (main merged in). Comment review, no findings.

What I checked:

  • tools/fuzz_cpu.py: count, input-file and output-path validation, atomic write with temp cleanup. Existing emit, translate, check behavior is kept.
  • tests/fuzz_cpu_cli_check.py (9 tests) guards the caller-visible result: exit code 1 with a short stderr message, and prior outputs left intact on write failure.
  • Mutations I ran, each makes the suite fail: count < 1 changed to count < 0 (1 failure), and the hardlink samefile check disabled (2 failures). Both reverted.
  • tests/fuzz_cpu_cli_check.py passes locally (9 tests, OK). git diff --check, docs_links_check, bidi_controls_check: clean.
  • No other open or merged PR covers this slice.
  • Windows Server 2025 WARP, ctest -R fuzz: dev 11/11 and release 11/11 passed. That includes the new tooling_fuzz_cpu_cli_check and the existing cpu_aot_fuzz* tests that use this script.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068020553 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2673#pullrequestreview-6068020553). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:08:17Z. **Review:** COMMENTED --- Review of head 36dbe7f3 (main merged in). Comment review, no findings. What I checked: - `tools/fuzz_cpu.py`: count, input-file and output-path validation, atomic write with temp cleanup. Existing `emit`, `translate`, `check` behavior is kept. - `tests/fuzz_cpu_cli_check.py` (9 tests) guards the caller-visible result: exit code 1 with a short stderr message, and prior outputs left intact on write failure. - Mutations I ran, each makes the suite fail: `count < 1` changed to `count < 0` (1 failure), and the hardlink `samefile` check disabled (2 failures). Both reverted. - `tests/fuzz_cpu_cli_check.py` passes locally (9 tests, OK). `git diff --check`, docs_links_check, bidi_controls_check: clean. - No other open or merged PR covers this slice. - Windows Server 2025 WARP, `ctest -R fuzz`: dev 11/11 and release 11/11 passed. That includes the new `tooling_fuzz_cpu_cli_check` and the existing `cpu_aot_fuzz*` tests that use this script. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:35 +00:00 (Migrated from github.com)

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


Win2025 WARP receipt for head 36dbe7f3 after updating with main.

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target cpu_fuzz cpu_fuzz_bits cpu_fuzz_bits_lifted cpu_fuzz_bits_mutant cpu_fuzz_calls cpu_fuzz_calls_lifted cpu_fuzz_calls_mutant cpu_fuzz_chains cpu_fuzz_chains_lifted cpu_fuzz_chains_mutant cpu_fuzz_frames cpu_fuzz_frames_lifted cpu_fuzz_frames_mutant cpu_fuzz_lifted cpu_fuzz_loops cpu_fuzz_loops_lifted cpu_fuzz_loops_mutant cpu_fuzz_rsp cpu_fuzz_rsp_lifted cpu_fuzz_rsp_mutant cpu_fuzz_scalar_fp cpu_fuzz_scalar_fp_lifted cpu_fuzz_scalar_fp_mutant cpu_fuzz_switches cpu_fuzz_switches_lifted cpu_fuzz_switches_mutant cpu_fuzz_x87 cpu_fuzz_x87_lifted cpu_fuzz_x87_mutant -- -j 2): 14.89s (configure 3.49s)
    • Test (ctest --preset dev -R 'fuzz' --parallel 2 --no-tests=error --output-on-failure): 11/11 passed (15.26s: cpu_aot_fuzz_smoke 0.71s, cpu_aot_fuzz_frames 0.68s, cpu_aot_fuzz_calls 1.00s, cpu_aot_fuzz_chains 0.69s, cpu_aot_fuzz_switches 1.65s, cpu_aot_fuzz_scalar_fp 2.02s, cpu_aot_fuzz_rsp 1.45s, cpu_aot_fuzz_loops 1.21s, cpu_aot_fuzz_x87 1.53s, cpu_aot_fuzz_bits 1.55s, tooling_fuzz_cpu_cli_check 15.08s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target cpu_fuzz cpu_fuzz_bits cpu_fuzz_bits_lifted cpu_fuzz_bits_mutant cpu_fuzz_calls cpu_fuzz_calls_lifted cpu_fuzz_calls_mutant cpu_fuzz_chains cpu_fuzz_chains_lifted cpu_fuzz_chains_mutant cpu_fuzz_frames cpu_fuzz_frames_lifted cpu_fuzz_frames_mutant cpu_fuzz_lifted cpu_fuzz_loops cpu_fuzz_loops_lifted cpu_fuzz_loops_mutant cpu_fuzz_rsp cpu_fuzz_rsp_lifted cpu_fuzz_rsp_mutant cpu_fuzz_scalar_fp cpu_fuzz_scalar_fp_lifted cpu_fuzz_scalar_fp_mutant cpu_fuzz_switches cpu_fuzz_switches_lifted cpu_fuzz_switches_mutant cpu_fuzz_x87 cpu_fuzz_x87_lifted cpu_fuzz_x87_mutant -- -j 2): 17.34s (configure 3.20s)
    • Test (ctest --preset release -R 'fuzz' --parallel 2 --no-tests=error --output-on-failure): 11/11 passed (15.47s: cpu_aot_fuzz_smoke 0.74s, cpu_aot_fuzz_frames 0.74s, cpu_aot_fuzz_calls 1.06s, cpu_aot_fuzz_chains 0.71s, cpu_aot_fuzz_switches 1.70s, cpu_aot_fuzz_scalar_fp 2.02s, cpu_aot_fuzz_rsp 1.40s, cpu_aot_fuzz_loops 1.04s, cpu_aot_fuzz_x87 1.33s, cpu_aot_fuzz_bits 1.54s, tooling_fuzz_cpu_cli_check 15.28s)
  • sccache: 46/72 hits; wall 62.5s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181428939 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2673#issuecomment-7181428939). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:08:17Z. --- Win2025 WARP receipt for head 36dbe7f3 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `36dbe7f33cf6e951252767b551ca2666bde702d5`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target cpu_fuzz cpu_fuzz_bits cpu_fuzz_bits_lifted cpu_fuzz_bits_mutant cpu_fuzz_calls cpu_fuzz_calls_lifted cpu_fuzz_calls_mutant cpu_fuzz_chains cpu_fuzz_chains_lifted cpu_fuzz_chains_mutant cpu_fuzz_frames cpu_fuzz_frames_lifted cpu_fuzz_frames_mutant cpu_fuzz_lifted cpu_fuzz_loops cpu_fuzz_loops_lifted cpu_fuzz_loops_mutant cpu_fuzz_rsp cpu_fuzz_rsp_lifted cpu_fuzz_rsp_mutant cpu_fuzz_scalar_fp cpu_fuzz_scalar_fp_lifted cpu_fuzz_scalar_fp_mutant cpu_fuzz_switches cpu_fuzz_switches_lifted cpu_fuzz_switches_mutant cpu_fuzz_x87 cpu_fuzz_x87_lifted cpu_fuzz_x87_mutant -- -j 2`): `14.89s` (configure `3.49s`) - Test (`ctest --preset dev -R 'fuzz' --parallel 2 --no-tests=error --output-on-failure`): **11/11 passed** (`15.26s`: `cpu_aot_fuzz_smoke` `0.71s`, `cpu_aot_fuzz_frames` `0.68s`, `cpu_aot_fuzz_calls` `1.00s`, `cpu_aot_fuzz_chains` `0.69s`, `cpu_aot_fuzz_switches` `1.65s`, `cpu_aot_fuzz_scalar_fp` `2.02s`, `cpu_aot_fuzz_rsp` `1.45s`, `cpu_aot_fuzz_loops` `1.21s`, `cpu_aot_fuzz_x87` `1.53s`, `cpu_aot_fuzz_bits` `1.55s`, `tooling_fuzz_cpu_cli_check` `15.08s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target cpu_fuzz cpu_fuzz_bits cpu_fuzz_bits_lifted cpu_fuzz_bits_mutant cpu_fuzz_calls cpu_fuzz_calls_lifted cpu_fuzz_calls_mutant cpu_fuzz_chains cpu_fuzz_chains_lifted cpu_fuzz_chains_mutant cpu_fuzz_frames cpu_fuzz_frames_lifted cpu_fuzz_frames_mutant cpu_fuzz_lifted cpu_fuzz_loops cpu_fuzz_loops_lifted cpu_fuzz_loops_mutant cpu_fuzz_rsp cpu_fuzz_rsp_lifted cpu_fuzz_rsp_mutant cpu_fuzz_scalar_fp cpu_fuzz_scalar_fp_lifted cpu_fuzz_scalar_fp_mutant cpu_fuzz_switches cpu_fuzz_switches_lifted cpu_fuzz_switches_mutant cpu_fuzz_x87 cpu_fuzz_x87_lifted cpu_fuzz_x87_mutant -- -j 2`): `17.34s` (configure `3.20s`) - Test (`ctest --preset release -R 'fuzz' --parallel 2 --no-tests=error --output-on-failure`): **11/11 passed** (`15.47s`: `cpu_aot_fuzz_smoke` `0.74s`, `cpu_aot_fuzz_frames` `0.74s`, `cpu_aot_fuzz_calls` `1.06s`, `cpu_aot_fuzz_chains` `0.71s`, `cpu_aot_fuzz_switches` `1.70s`, `cpu_aot_fuzz_scalar_fp` `2.02s`, `cpu_aot_fuzz_rsp` `1.40s`, `cpu_aot_fuzz_loops` `1.04s`, `cpu_aot_fuzz_x87` `1.33s`, `cpu_aot_fuzz_bits` `1.54s`, `tooling_fuzz_cpu_cli_check` `15.28s`) - `sccache`: 46/72 hits; wall `62.5s` 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!2665
No description provided.