x64_recomp: a buffer that ends inside a VEX/EVEX prefix is a DecodeError (X64-RECOMP-VEX-BOUNDS) #1121
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1121"
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 ubiquitarianism/leonida. Originally posted by kett1m on 2026-11-24T18:50:36Z.
Claimed in the coordination issue as: X64-RECOMP-VEX-BOUNDS
Depends on: #1120
What and why
decode_one's docstring promises it never reads pastend, but the VEX/EVEX prefix pathbroke that promise in three places. The three-byte VEX form read
buf[pos+2]behind apos + 1 < endguard, and both VEX forms and EVEX read the opcode that follows the prefixat
buf[pos]after advancingpospastend, unchecked. A buffer that ends inside aprefix raised
IndexError, whichdisasm()does not catch (it catchesDecodeErroronly), so the walk died.
Measured on the retail Xbox Series image (
game_scarlett_master.exe, SHA-256e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993) with REAinspect_with_objdump. Section-header evidenceev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90maps.textRVA0x140001000to file0x400and.pdataRVA0x14abcf000to file0x6e03a00;file-header evidence
ev_4ec749bb6395770cf8a099344c042bfd7ba67ff269f47e7ae115443028d4e127gives entry
0x1456a1ec8. The unfixed walk abortedpython3 -I tools/recomp_census.py <exe>with
IndexError: index out of rangeattools/x64_recomp.pyline 532, reached through thevzeroupper desync fixed in #1120.
The fix raises
DecodeErrorwhere the prefix loop and the REX path already do, so a cutprefix is a reported gap rather than a crash. With #1120 in, no
.pdatafunction of theretail image reaches this path any more (0 of 299,257); the bound is what keeps a buffer a
caller really cut, at a
.pdataor disassembly boundary, from killing the caller.Tested
python3 -I tests/test_x64_recomp.py: 36 tests OK, 26 qemu skips.python3 -I tests/test_recomp_census.py: 9 tests OK.test_truncated_vex_and_evex_are_decode_errorscovers the four prefix shapes at the end ofa buffer.
test_never_reads_past_enddecodes every sequence of one to four bytes over a28-byte alphabet of prefixes, REX bytes, escape bytes and opcodes (637,420 sequences) and
requires each to stay inside the buffer or raise
DecodeError. Both fail against theunfixed decoder (
IndexError: index out of rangeonc462, and the four shapes). Thecensus-level test shows a
.pdatafunction cut inside a prefix is now a decode gap.python3 -m compileall -q make_game.py tools tests: exit 0.python3 -I scripts/check_no_game_data.py tools/x64_recomp.py tests/test_x64_recomp.py tests/test_recomp_census.py: exit 0, no output.The tests are synthetic bytes and a byte-built PE; no game files.
GPUs tested: n/a (decoder and census are CPU-only)
AI-assisted: yes (DeepSeek V4.1 Flash)
Checklist
mainand merges cleanly after #1120.docs/design.mdcontract row.Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T18:56:08Z.
Review: APPROVED
Reviewed and verified. Resolves unhandled
IndexErrorinx64_recomp.py:decode_onewhen buffers terminate inside 3-byte VEX (0xC4) or EVEX prefixes. Safely bounds prefix reads and raisesDecodeErrorper contract, allowing disassemblers to report gaps gracefully. Verified withtests/test_x64_recomp.pyandtests/test_recomp_census.py. 100% clean-room.Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:15:46Z.
Recommendation: [WAIT]
Reasoning: A buffer ending inside a VEX/EVEX prefix now raises
DecodeErrorinstead of an uncaughtIndexError, fixing three out-of-bounds reads indecode_one. The change itself looks good and is tested. It depends on #1120: merge that first, then rebase this. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict withmain.Impact level: 3/10
Imported from ubiquitarianism/leonida. Originally posted by kevincommits on 2026-11-26T04:44:34Z.
Independent run. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, LLVM from Homebrew. I merged
mainata73a57e13into the branch locally (1,098 commits behind; three files auto-merged, no conflicts). Head tested:84239b50b.On 200,000 random buffers
mainreads past the end of the buffer 5,059 times; this branch never does.Random buffers through
decode_one. 1–8 bytes each, fixed seed, half of them starting with a run of prefix and escape bytes (62 c4 c5 0f 66 67 f0 f2 f3 2e 64 65 48 40 4f), the same inputs on both trees:DecodeErrorIndexErrormainThe first
mainfailure is the two-byte bufferc4 0f. Every one of the 5,059 becomes aDecodeErroror a clean decode here, and nothing that decoded cleanly onmainstops decoding.vzeroupper/vzeroalllength checked against an independent decoder.llvm-mc --disassemble -triple=x86_64 -mattr=+avxgivesc5 f8 77=vzeroupperandc5 fc 77=vzeroall, 3 bytes each, with the followingc3as its ownretq, as the new tests expect.Counts on the merged tree.
tests/test_x64_recomp.py48/48 (main: 44) andtests/test_recomp_census.py13/13 (main: 11). Full standalone suite: 513 run, 512 pass; the 1 that fails ismain'stest_mod_pack_output_alias.Overlap. #1246 adds a test at the same spot in both test files (
test_prefixesintests/test_x64_recomp.py, the edge tests intests/test_recomp_census.py); whichever lands second will need a small rebase. I did not merge the two together.Not tested: execution (the change is decode-only) and buffers longer than 8 bytes. No game files used. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:58:53Z.
Hi @kett1m, thanks for this pull request. It currently conflicts with
main(conflicting file(s):tests/test_x64_recomp.py), so it carries theneeds rebaselabel. CONTRIBUTING.md asks authors to rebase their branch onmain; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:40:05Z.
Review: COMMENTED
Reviewed the diff against
main: the VEX/EVEX truncationDecodeErrorguards intools/x64_recomp.py:568-595and exhaustive tests intests/test_x64_recomp.py:95-121look solid and clean-room verified. Holding approval/merge because this PR is stacked on unmerged#1120and has stale failing CI — once#1120lands, please rebase ontomainso CI runs cleanly.(AI-assisted review.)
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:48:30Z.
For information: this pull request is carried in #3101, which merges your head
72eedf158(your commits are kept) into currentmainand resolves the conflict intests/test_x64_recomp.pyby keeping main's tests and your two new ones. Nothing else changes. If you rebase this one yourself, say so and #3101 can be closed.AI-assisted (Claude Code).