[PR #1121] x64_recomp: a buffer that ends inside a VEX/EVEX prefix is a DecodeError (X64-RECOMP-VEX-BOUNDS) #1156

Open
opened 2026-11-26 20:20:16 +01:00 by 4ld0 · 0 comments
Owner

📋 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)

  • 7b78bd6 x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM)
  • 84239b5 x64_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 past end, but the VEX/EVEX prefix path
broke that promise in three places. The three-byte VEX form read buf[pos+2] behind a
pos + 1 < end guard, and both VEX forms and EVEX read the opcode that follows the prefix
at buf[pos] after advancing pos past end, unchecked. A buffer that ends inside a
prefix raised IndexError, which disasm() does not catch (it catches DecodeError
only), so the walk died.

Measured on the retail Xbox Series image (game_scarlett_master.exe, SHA-256
e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993) with REA
inspect_with_objdump. Section-header evidence
ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90 maps .text RVA
0x140001000 to file 0x400 and .pdata RVA 0x14abcf000 to file 0x6e03a00;
file-header evidence ev_4ec749bb6395770cf8a099344c042bfd7ba67ff269f47e7ae115443028d4e127
gives entry 0x1456a1ec8. The unfixed walk aborted python3 -I tools/recomp_census.py <exe>
with IndexError: index out of range at tools/x64_recomp.py line 532, reached through the
vzeroupper desync fixed in #1120.

The fix raises DecodeError where the prefix loop and the REX path already do, so a cut
prefix is a reported gap rather than a crash. With #1120 in, no .pdata function of the
retail image reaches this path any more (0 of 299,257); the bound is what keeps a buffer a
caller really cut, at a .pdata or 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_errors covers the four prefix shapes at the end of
a buffer. test_never_reads_past_end decodes every sequence of one to four bytes over a
28-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 the
unfixed decoder (IndexError: index out of range on c462, and the four shapes). The
census-level test shows a .pdata function 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

  • Based on current main and merges cleanly after #1120.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • No new translator rule, so no docs/design.md contract row.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1121 **Author:** [@kett1m](https://github.com/kett1m) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `x64-recomp-vex-bounds` --- ### 📝 Commits (2) - [`7b78bd6`](https://github.com/ubiquitarianism/leonida/commit/7b78bd6637a1d958e707669c24e1caf88558affc) x64_recomp: vzeroupper is three bytes, not four (X64-RECOMP-VZEROUPPER-NO-MODRM) - [`84239b5`](https://github.com/ubiquitarianism/leonida/commit/84239b50b2af3e040a911727583de8edac260469) x64_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) <details> <summary>View changed files</summary> 📝 `tests/test_recomp_census.py` (+49 -0) 📝 `tests/test_x64_recomp.py` (+45 -0) 📝 `tools/x64_recomp.py` (+20 -1) </details> ### 📄 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 past `end`, but the VEX/EVEX prefix path broke that promise in three places. The three-byte VEX form read `buf[pos+2]` behind a `pos + 1 < end` guard, and both VEX forms and EVEX read the opcode that follows the prefix at `buf[pos]` after advancing `pos` past `end`, unchecked. A buffer that ends inside a prefix raised `IndexError`, which `disasm()` does not catch (it catches `DecodeError` only), so the walk died. Measured on the retail Xbox Series image (`game_scarlett_master.exe`, SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`) with REA `inspect_with_objdump`. Section-header evidence `ev_e29cbdffd0dc7c46889b2a1f955011ce9f2795017233c97107ded73f9186dd90` maps `.text` RVA `0x140001000` to file `0x400` and `.pdata` RVA `0x14abcf000` to file `0x6e03a00`; file-header evidence `ev_4ec749bb6395770cf8a099344c042bfd7ba67ff269f47e7ae115443028d4e127` gives entry `0x1456a1ec8`. The unfixed walk aborted `python3 -I tools/recomp_census.py <exe>` with `IndexError: index out of range` at `tools/x64_recomp.py` line 532, reached through the vzeroupper desync fixed in #1120. The fix raises `DecodeError` where the prefix loop and the REX path already do, so a cut prefix is a reported gap rather than a crash. With #1120 in, no `.pdata` function of the retail image reaches this path any more (0 of 299,257); the bound is what keeps a buffer a caller really cut, at a `.pdata` or 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_errors` covers the four prefix shapes at the end of a buffer. `test_never_reads_past_end` decodes every sequence of one to four bytes over a 28-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 the unfixed decoder (`IndexError: index out of range` on `c462`, and the four shapes). The census-level test shows a `.pdata` function 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 - [x] Based on current `main` and merges cleanly after #1120. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports quoted here. - [x] No new translator rule, so no `docs/design.md` contract row. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1156
No description provided.