tooling: harden fuzz_cpu CLI path/count guards and atomic writes #2665
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2673"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:44:09Z.
Change
Harden
tools/fuzz_cpu.pyCLI input/output validation and atomic file writes acrossemit,translate, andcheck, and add a pure-Python CLI test suite (tests/fuzz_cpu_cli_check.py) registered inCMakeLists.txtastooling_fuzz_cpu_cli_check(TIMEOUT 60)._write_atomic(path, text)creating missing parent directories, writing UTF-8 with LF newlines, replacing viaos.replace, and unlinking temporary files on any failure.count >= 1upfront inemit(),translate(), andrun_check()._validate_input_file()intranslate()andrun_check()(including optional--mutant).asm,definition,output) upfront via_validate_output_path()(rejecting symlinks, directories, and non-directory parents) and_validate_distinct_paths()(rejecting identical/overlapping/hardlink-samefileasmvsdefinitionandoutputvsimagepaths).(OSError, ValueError, struct.error, KeyError, *_PE_ERRORS)cleanly inmain()with concise stderr and exit code1(zero raw tracebacks), preserving existing CMakecpu_aot_fuzz*behavior.Verification
01e1c5c3(based onupstream/main82c70807)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)_validate_count,_validate_distinct_pathshardlinksamefilecheck,_write_atomictemp unlink cleanup).count <= 0across all 3 subcommands, missing/directory PE paths intranslateandcheck(including--mutant), corrupt PE intranslate, output directory/symlink/file-parent/ancestor-file/collision/hardlink guards, simulatedos.replaceand staging write failures preserving prior outputs with zero.tmpfiles, and Python 3.14-safe argparse checks.Evidence and follow-up
All fixtures in
tests/fuzz_cpu_cli_check.pyare pure-Python generated temporary inputs and mocked lifter calls under the repository MIT license; no external binaries or game files are used.Checklist
AI-assisted.
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. Existingemit,translate,checkbehavior 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.count < 1changed tocount < 0(1 failure), and the hardlinksamefilecheck disabled (2 failures). Both reverted.tests/fuzz_cpu_cli_check.pypasses locally (9 tests, OK).git diff --check, docs_links_check, bidi_controls_check: clean.ctest -R fuzz: dev 11/11 and release 11/11 passed. That includes the newtooling_fuzz_cpu_cli_checkand the existingcpu_aot_fuzz*tests that use this script.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:08:17Z.
Win2025 WARP receipt for head
36dbe7f3after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
36dbe7f33cf6e951252767b551ca2666bde702d5:--preset dev):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(configure3.49s)ctest --preset dev -R 'fuzz' --parallel 2 --no-tests=error --output-on-failure): 11/11 passed (15.26s:cpu_aot_fuzz_smoke0.71s,cpu_aot_fuzz_frames0.68s,cpu_aot_fuzz_calls1.00s,cpu_aot_fuzz_chains0.69s,cpu_aot_fuzz_switches1.65s,cpu_aot_fuzz_scalar_fp2.02s,cpu_aot_fuzz_rsp1.45s,cpu_aot_fuzz_loops1.21s,cpu_aot_fuzz_x871.53s,cpu_aot_fuzz_bits1.55s,tooling_fuzz_cpu_cli_check15.08s)/O2(--preset release):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(configure3.20s)ctest --preset release -R 'fuzz' --parallel 2 --no-tests=error --output-on-failure): 11/11 passed (15.47s:cpu_aot_fuzz_smoke0.74s,cpu_aot_fuzz_frames0.74s,cpu_aot_fuzz_calls1.06s,cpu_aot_fuzz_chains0.71s,cpu_aot_fuzz_switches1.70s,cpu_aot_fuzz_scalar_fp2.02s,cpu_aot_fuzz_rsp1.40s,cpu_aot_fuzz_loops1.04s,cpu_aot_fuzz_x871.33s,cpu_aot_fuzz_bits1.54s,tooling_fuzz_cpu_cli_check15.28s)sccache: 46/72 hits; wall62.5sAI-assisted; commands listed were executed locally.