mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:30:52 +01:00
[PR #1121] x64_recomp: a buffer that ends inside a VEX/EVEX prefix is a DecodeError (X64-RECOMP-VEX-BOUNDS) #1156
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1156
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1121
Author: @kett1m
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:x64-recomp-vex-bounds📝 Commits (2)
7b78bd6x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM)84239b5x64_recomp: a buffer that ends inside a VEX/EVEX prefix is a DecodeError (X64-RECOMP-VEX-BOUNDS)📊 Changes
3 files changed (+114 additions, -1 deletions)
View changed files
📝
tests/test_recomp_census.py(+49 -0)📝
tests/test_x64_recomp.py(+45 -0)📝
tools/x64_recomp.py(+20 -1)📄 Description
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.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.