tooling: harden bink_frame_aot anchor validation and add unit suite #1961
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1968"
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-24T22:16:36Z.
Change
Harden anchor lookup and CLI error handling in
tools/bink_frame_aot.pyand add an offline synthetic AMD64 PE32+ validation suite (bink_frame_aot_check) intests/bink_frame_aot_check.py, registered inCMakeLists.txt.next(...)generator lookups for themov rdi, rdxandxor eax, eaxslice anchors ingenerate()with explicitValueErrordiagnostics when either anchor is missing orxor eax, eaxprecedesmov rdi, rdx, instead of leakingStopIteration.main(argv=None) -> intintools/bink_frame_aot.pyso(OSError, ValueError, pefile.PEFormatError)failures exit cleanly with code1and an error message on stderr instead of printing a Python traceback.tests/bink_frame_aot_check.pycovering positive C++ lowering output and CLI invocation, plus negative controls for missing input files, SHA-256 profile mismatches, missingBinkAllocateFrameBuffersexport, missing/inverted anchors, call-count and indirect-call rejections, mismatched helper RVAs, malformed PE inputs, and invalid.cpp/same-path CLI arguments.Verification
.\out\pe-env\Scripts\python.exe -B tests/bink_frame_aot_check.py -v->Ran 7 tests in 3.073s(OK).tools/bink_frame_aot.pytoupstream/main):Ran 7 tests->FAILED (failures=2, errors=2)(StopIterationon missing anchor, missingmain, tracebacks on missing/non-PE CLI inputs).devpreset (cmake --preset dev,ctest --preset dev -N->Total Tests: 1251):ctest --preset dev --no-tests=error -R "^(bink_frame_aot_check|bink_heap_aot_check|cpu_aot_bink_heap|cpu_aot_bink_group)$" -V->4/4passed (cpu_aot_bink_heap,cpu_aot_bink_group,bink_heap_aot_check12/12,bink_frame_aot_check7/7).releasepreset (cmake --preset release,ctest --preset release -N->Total Tests: 1251):ctest --preset release --no-tests=error -R "^(bink_frame_aot_check|bink_heap_aot_check|cpu_aot_bink_heap|cpu_aot_bink_group)$" -V->4/4passed.tests/form_coverage_check.py,tests/docs_links_check.py, andtests/bidi_controls_check.pyall exited0.Evidence and follow-up
tests/bink_frame_aot_check.pyconstructs a minimal synthetic AMD64 PE32+ DLL in memory (two leaf helpers,BinkAllocateFrameBufferswith the expected control-flow/call shape, export directory,.pdata, andUNWIND_INFO) with no external binaries or game files;BINK_SHA256is patched in-memory only for synthetic-image tests.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T22:27:48Z.
Ran it and broke all five new behaviours
Windows 11 build 26300.9974:
Mutations to
tools/bink_frame_aot.py, each reverted:if first is None:→if False:(missingmov rdi, rdx→StopIteration)if failure is None:→if False:(missingxor eax, eax→StopIteration)if failure <= first:→if False:(inverted anchor order accepted)except (OSError, ValueError, pefile.PEFormatError)→except (KeyboardInterrupt,)parser.exit(1, …)→parser.exit(0, …)The inverted-order case is the one I expected to slip: both anchors still exist, so a generator-based lookup would pass and the
slice would simply be taken over the wrong range, producing plausible C++ from the wrong bytes. The fixture refuses it.
Why the three anchor guards matter here specifically
next(...)without a default raisesStopIteration, and inside a generator that is not an error a caller sees — it terminates theenclosing iteration silently. A
generate()that returned a truncated or empty translation instead of failing is exactly thefailure mode a report would not notice, so replacing it with
ValueErrorplus a message is the right shape, and the three casesare pinned independently.
What this does not establish
Nothing about the real package image: the fixture is a synthetic PE32+ with the anchors placed by the test. The SHA-256 profile
comparison is exercised only against the synthetic image, and the translated function is not linked or run. That matches the
description's scope.
One note
import pefileadded at module level means the tool now fails at import time on a machine withoutpefile, rather than at thefirst
generate(). Since the check is registered as a CTest that runs the CLI, a missing dependency surfaces as a failed testinstead of a skip — if that is not wanted, the import could move inside
generate(). Not a defect, just the usual question aboutwhere a third-party import belongs in a tool that CI runs unconditionally.
Verdict
Reviewed. Three anchor refusals and both CLI behaviours are pinned, and the inverted-order case is the interesting one.
Notes