tooling: harden atomic writes, path guards, and CLI entry in cpu_leaf_aot with synthetic PE32+ suite #3111
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!3111
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3111"
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 15:45 UTC · original
Ammmae0x:tooling/cpu-leaf-aot-cli→main· +763 −4 · 3 files · 1 commits · merged 2026-11-27 20:41 UTCChange
Harden
tools/cpu_leaf_aot.pyCLI argument handling, path validation, and atomic output writes, and add a standalone pure-Python synthetic PE32+ verification suite:main(argv=None) -> intand runraise SystemExit(main())underif __name__ == "__main__"._validate_paths(image exists and is not a directory, non-empty export string,.cppoutput suffix, output is not a symlink or directory, no output ancestor is a file/non-directory, and output does not alias image viaresolve()orsamefile()).write_textwith sibling-temp atomic writes in_write_atomic(creating missing parent directories and unlinking temp files on any failure).translate(start, code)against boolean/negativestartRVAs and non-bytes-likecodewhile preserving existingexport_rva,bounded_code,function_bytes, andtranslatebehavior.tests/cpu_leaf_aot_cli_check.py(unit, CLI, path-guard, symlink, atomic-write failure, malformed synthetic PE32+, and fast self-mutation tests) and registertooling_cpu_leaf_aot_cli_check(TIMEOUT 60) intests/cmake/tooling_cpu_leaf_aot_cli.cmake.Verification
Verified on commit
4db40e97in the primary workspace:out\pe-env\Scripts\python.exe -B tests/cpu_leaf_aot_cli_check.py -v->Ran 8 tests ... OK(exit 0, including 10 fast mutations).out\pe-env\Scripts\python.exe -B tests/cpu/malformed_pe_check.py->ok(exit 0).out\pe-env\Scripts\python.exe -B tests/cpu_ranges_check.py -v->Ran 5 tests ... OK(exit 0).out\pe-env\Scripts\python.exe -B -c "import sys; sys.path.insert(0, 'tests/cpu'); import branches; branches.check_rejections()"-> 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 87 Markdown files and 586 links.(exit 0).out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 2293 tracked source, script and build/CI files: no bidirectional controls.(exit 0).tools/cpu_leaf_aot.py: 3/3 mutations killed (_validate_pathsbypassed -> exit 1, 15 failures;_write_atomicreplaced -> exit 1, 4 failures;start < 0guard bypassed -> exit 1, 2 failures).Evidence and follow-up
All synthetic PE32+ fixtures are generated directly in
tests/cpu_leaf_aot_cli_check.py; no external binaries or game files are used.Checklist
AI-assisted.
@KelboLive on GitHub · 2026-11-27 18:54 UTC · original · approved these changes
@pigalot on GitHub · 2026-11-27 20:41 UTC · original · approved these changes
I reviewed
4db40e97merged over currentmain5fc9f6ff. The merge is clean (tree7b1f56a5) andgit diff --cached --checkis clean.What I traced.
cpu_translation(cpu_leaf_${variant} cpu_leaf_aot branch_value)inCMakeLists.txt. It writes<image>_lifted.cpp, so the new.cppsuffix rule and the path guards don't refuse anything the build does.export_rvaandbounded_code, which are unchanged.translatehas one outside caller,tests/cpu/branches.py, and it passes anintandbytes._validate_pathsraisesValueError,IsADirectoryErrororNotADirectoryError. All three are caught by the existingexcept (ValueError, OSError, pefile.PEFormatError), so a refusal still exits 1 with one line on stderr, the same as main'sparser.exit(1, ...).cpu_leaf_original.dll, main's tool and the PR's tool produce the same C++ apart from line endings (next point).What I ran. I built
cpu_leaf_original,cpu_leaf_inverted(and their_liftedDLLs) andcpu_flag_conditionsindevandrelease, then ran5/5 pass in both presets.
out\pe-env\Scripts\python.exe -B tests/cpu_leaf_aot_cli_check.py -vruns 8 tests, OK, with no skips: this account can create symlinks, sotest_output_symlink_rejected_upfrontreally ran.Mutants in
tools/cpu_leaf_aot.py, each run againsttests/cpu_leaf_aot_cli_check.py:.suffix.lower()→.suffixstart < 0→start < -1os.replace→ copy then unlinkresolve()samefile()is_dir()guard removednewline="\n"removedexcept BaseException→except ExceptionNon-blocking notes.
newline="\n"changes the generated file's bytes: main'swrite_textwrites CRLF (55 line ends forbranch_value), and the PR writes LF. The content is otherwise identical and MSVC doesn't care, but the body says existing behavior is preserved. A sentence in the body, or a test that pins LF output, would make it deliberate. No test pins it today (mutant above).BaseExceptioncleanup isn't tested. The temp-file cleanup is only tested withExceptionsubclasses. AKeyboardInterruptraised from the patchedos.replacewould cover theBaseExceptionbranch.tests/checks/python-linux/cpu_leaf_aot_cli.txtline would also run it on Linux, where the symlink case never skips.Verdict: approve on
4db40e97.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 on4db40e97.This reply was AI-assisted.