cpu: harden cpu_chained_aot CLI validation and atomic writes #3131
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3131
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3129"
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?
@Ammmae0x on GitHub · 2026-11-27 16:21 UTC · original
Ammmae0x:cpu/chained-aot-cli→main· +535 −6 · 4 files · 1 commits · merged 2026-11-27 21:15 UTCChange
Harden
tools/cpu_chained_aot.pyCLI validation, callback-offset type checking, and atomic output writes, and add a standalone pure-Python synthetic PE32+ verification suite:main(argv=None) -> intand invokeraise SystemExit(main())underif __name__ == "__main__"._validate_cli_inputs(input image is an existing file, non-empty export name,.cppoutput suffix, output is not a symlink or directory, output parent is not a file/non-directory, and output does not collide with the input image viaresolve()orsamefile()) and exit1cleanly on(ValueError, OSError, pefile.PEFormatError).translate()against empty/non-string export names and reject non-intcallback_offsetvalues (explicitly rejectingboolFalse/Trueviatype(callback_offset) is not int) alongside0 <= callback_offset <= 0x7fffffffand 8-byte alignment.write_textwith sibling-temp atomic writes in_write_atomic, creating missing parent directories and closing/unlinking temp files on all failure paths.tests/cpu_chained_aot_cli_check.py(synthetic chained,--partial,--callback-offset,--ffx-destroy, hostile paths,bool/negative/unaligned/overflow offset refusals,os.replace/os.fdopenfailure cleanup, and 5 fast self-mutations) and registercpu_chained_aot_cli_checkviatests/cmake/cpu_chained_aot_cli.cmakeandtests/checks/python-linux/cpu_chained_aot_cli.txt.Verification
Verified on commit
dcf9f44einslot-2:out\pe-env\Scripts\python.exe -B tests/cpu_chained_aot_cli_check.py -v->Ran 5 tests ... OK(exit 0, including 5 fast self-mutations).ctest --preset dev --no-tests=error -R "^(cpu_chained_aot_cli_check|cpu_aot_chained_ranges|cpu_aot_object_callback|cpu_aot_chained_dead_reads)$" --output-on-failure->4/4 passed(exit 0).out\pe-env\Scripts\python.exe -B tests/cpu/malformed_pe_check.py->ok(exit 0).out\pe-env\Scripts\python.exe -B tests/run_checks_fragments_check.py->run_checks_fragments_check 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 96 Markdown files and 586 links.(exit 0).out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 2311 tracked source, script and build/CI files: no bidirectional controls.(exit 0).tools/cpu_chained_aot.py: 3/3 mutations killed (droptype(callback_offset) is not int-> exit 1; disable_validate_cli_inputsinmain()-> exit 1; disabletmp_path.unlinkin_write_atomic-> exit 1).Evidence and follow-up
All synthetic PE32+ fixtures are generated directly in
tests/cpu_chained_aot_cli_check.py; no external binaries or game files are used.Checklist
AI-assisted.
github-bot referenced this pull request2026-11-27 18:07:21 +00:00
@KelboLive on GitHub · 2026-11-27 18:50 UTC · original · approved these changes
Consistent hardening of
cpu_chained_aot.pyfollowing the same pattern as recent CLI validation PRs. The extractedmain(argv), path guards, atomic writes with proper cleanup, and explicit bool rejection for callback_offset are all correct. The synthetic PE32+ test suite covers hostile paths, collision detection, and mutation survival effectively. Approved.@pigalot on GitHub · 2026-11-27 21:14 UTC · original · approved these changes
I reviewed
dcf9f44emerged over currentmaincf3df832. The merge is clean (treecea67e3d) andgit diff --cached --checkis clean.What I traced.
cpu_translation(... cpu_chained_aot ...)rules:choose_value×5,cpu_chained_dead_read,call_context CALLBACK_OFFSET 8, andrelease_context FFX_DESTROY. Each writes${BIND_NAME}.cpp, so the new guards refuse nothing the build does.tests/cpu/callback_check.py,tests/cpu/chained_check.pyandtests/cpu/chained_dead_read_check.pyimporttranslate. All three pass a string name and anint(or no)callback_offset, so the newnameandtype(callback_offset) is not intguards accept them._write_atomic: ifos.fdopenraises,fd_openstays true and the descriptor is closed. Once thewithblock owns it, only the temp file is unlinked. Both paths are tested (see theclose-fdandunlinkmutants below).write_texttranslates newlines.What I ran. I did a full build in
devandrelease, then ran10/10 pass in both presets.
tests/cpu_chained_aot_cli_check.py -vruns 5 tests, OK, with no skips.Mutants in
tools/cpu_chained_aot.py, each run against the new check:type(...) is not int→isinstance(letsTruethrough)translatename guard removedis_file()guard removedis_dir()guard removedsamefile()alias check removedos.close(fd)removed0x7fffffff→0xfffffffftranslaterefuses the same name)resolve()comparison removedis_file()means the image exists, so an alias that resolves to it also exists andsamefile()catches it).suffix.lower()→.suffixexcept BaseException→except Exceptionnewline="\n"→NoneNon-blocking.
out.CPPcase would pin the case-insensitive suffix rule.KeyboardInterruptraised from a patchedos.replacewould pin theBaseExceptioncleanup, and a byte check would pin LF output.mkdirraises anOSError, and the handler turns that into exit 1. So this is consistent, just less direct than theoutput.parentsloop in #3111.Verdict: approve on
dcf9f44e.Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10.
CI:
Build and test on Windows,Assemble and translate gfx1013 fixturesandRun platform-independent Python checks on Linuxpass ondcf9f44e.This reply was AI-assisted.