tooling: harden bink_descriptors_aot CLI path guards and atomic writes #2662
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2670"
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:38:29Z.
Change
Harden
tools/bink_descriptors_aot.pyCLI argument validation and atomic output writing, and add a pure-Python synthetic PE32+ CLI test suite (tests/bink_descriptors_aot_cli_check.py) registered inCMakeLists.txtastooling_bink_descriptors_aot_cli_check(TIMEOUT 60)._validate_args(args, parser)validating upfront before code generation thatargs.imageis a regular file (rejecting directories and missing paths), and thatargs.outputhas a.cppsuffix, is not a symlink, directory, or non-directory-parent path, and is notresolve()-equal orsamefile()-equal toargs.image._write_atomic(path, content)creating missing parent directories, writing ASCII text to a sibling.tmpfile, replacingpathviaos.replace, and unlinking the temporary file on any exception so failed writes leave zero.tmpfiles.(OSError, ValueError, struct.error, pefile.PEFormatError)cleanly inmain()with non-zero exit and zero raw tracebacks.Verification
890a5841(based onupstream/main72879797)out\pe-env\Scripts\python.exe -B tests\bink_descriptors_aot_cli_check.py->Ran 8 tests in 11.088s / OK(exit 0)out\pe-env\Scripts\python.exe -B tests\bink_descriptors_aot_check.py->Ran 9 tests in 2.848s / 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 1894 tracked source, script and build/CI files: no bidirectional controls.(exit 0)args.output.is_symlink(),args.image.samefile(args.output),tmp_path.unlink(missing_ok=True))..cpp/empty/same-path/hardlink-samefile/directory/file-parent/ancestor-file/live-symlink/dangling-symlink outputs (verifyinggenerate()and_write_atomic()are never called), simulatedos.replaceand write failures preserving existing target bytes with zero.tmpfiles, and Python 3.14-safe argparse checks.Evidence and follow-up
All test inputs in
tests/bink_descriptors_aot_cli_check.pyuse the synthetic AMD64 PE32+ builder fromtests/bink_descriptors_aot_check.pyunder the repository MIT license; no external binaries or game files are used. Existingtests/bink_descriptors_aot_check.pyand generated C++ output remain unchanged.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:00:50Z.
Review: COMMENTED
Review of head
890a5841(bink_descriptors_aot.pyCLI path guards and atomic writes).Result: no blocking findings.
What I checked
_validate_args: image must be a file; output must end in.cpp, must not be a symlink or directory, parents must be directories; output equal to the image (resolve/samefile) is refused. All covered by the new CLI check._write_atomic: temp file in the output directory,os.replace, temp unlinked on failure.mainnow reportsOSError,ValueError,struct.errorandpefile.PEFormatErroras a clean error instead of a traceback.tooling_bink_descriptors_aot_cli_checkadded.os.replacewith a plainwrite_textmakes the new check fail (2 failures); disabling the symlink guard makes it fail (2 failures).Non-blocking notes
write_textgave the umask default. Harmless for a generated.cppin a build tree, but achmodto the umask default would keep the old behavior.Commands run (Linux, worktree at the PR head)
python3 -B tests/bink_descriptors_aot_cli_check.py(8 OK),tests/bink_descriptors_aot_check.py(9 OK),tests/form_coverage_check.py,tests/docs_links_check.py,tests/bidi_controls_check.py: all passgit diff --check origin/main...HEAD: cleanWin2025 (Build 26100, MSVC 14.44, D3D12 WARP) at
890a5841:x2w_pipe.py win2025 2670 --wait 7200 --keep-release: PASS (debug and release builds).The PR is 43 commits behind main. I did not update the branch. Merge left to the maintainers.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:05:00Z.
Review: COMMENTED
Review of head
f77c41b8(main merged in), comment only.Checked:
_validate_argsintools/bink_descriptors_aot.pyrejects directory or missing image, non-.cppoutput, symlink or directory output, non-directory parents, and output equal to the image (byresolve()andsamefile()). All run before code generation._write_atomicwrites a sibling temp file and usesos.replace. The temp file is removed on any exception, so failures leave no.tmp.main()now also catchesstruct.error, so malformed images exit 1 without a traceback.tooling_bink_descriptors_aot_cli_checksits next to the existingbink_descriptors_aot_check.Commands run locally:
git diff --check origin/main...HEAD. I read the new code paths by hand. The suite needspefile, which is not installed on the Linux box, so I did not run mutations there; the suite ran on Win2025 only.Minor, not blocking:
NamedTemporaryFilecreates the file with mode 0600, so the replaced.cppkeeps that mode on POSIX. Harmless on Windows.No blocking findings.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:05:02Z.
Win2025 WARP receipt for head
f77c41b8after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
f77c41b820de3bb1876aee7c92582b096c0b1be4:--preset dev):cmake --build --preset dev --target cpu_bink_descriptors_lifted cpu_bink_frame_to_heap_objects -- -j 2):1.07s(configure3.65s)ctest --preset dev -R 'bink_descriptors' --parallel 2 --no-tests=error --output-on-failure): 3/3 passed (9.60s:cpu_bink_descriptors0.15s,bink_descriptors_aot_check2.68s,tooling_bink_descriptors_aot_cli_check9.21s)/O2(--preset release):cmake --build --preset release --target cpu_bink_descriptors_lifted cpu_bink_frame_to_heap_objects -- -j 2):9.62s(configure3.37s)ctest --preset release -R 'bink_descriptors' --parallel 2 --no-tests=error --output-on-failure): 3/3 passed (8.93s:cpu_bink_descriptors0.12s,bink_descriptors_aot_check2.74s,tooling_bink_descriptors_aot_cli_check8.57s)sccache: 57/59 hits; wall34.3sAI-assisted; commands listed were executed locally.