x64_recomp: a buffer that ends inside a VEX/EVEX prefix is a DecodeError (X64-RECOMP-VEX-BOUNDS, carry of #1121) #3101

Merged
MoonEyes merged 3 commits from upstream-pr/3101 into main 2026-12-02 11:17:51 +00:00
MoonEyes commented 2026-12-02 10:48:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:48:17Z.


Claimed in the coordination issue as: X64-RECOMP-VEX-BOUNDS (the claim of the original author, https://github.com/ProjectLeonida/mandy/issues/14#issuecomment-7140338734)

Depends on: #1120 (merged)

What and why

Carry of #1121 (kett1m), in conflict with main since tests/test_x64_recomp.py changed on both sides. This branch is main merged with the head of #1121 (72eedf158), so the author's commits are kept. My only change is the merge: main's tests and the PR's two new tests both stay.

The change itself is #1121's: decode_one promises never to read past end, but a buffer ending inside a two- or three-byte VEX prefix or an EVEX prefix indexed one byte past it and raised IndexError, which callers that only catch DecodeError (tools/recomp_census.py) did not survive. It now raises DecodeError. test_truncated_vex_and_evex_are_decode_errors pins the four truncated forms and test_never_reads_past_end checks every sequence up to four bytes of a prefix/opcode alphabet.

Tested

Windows 11, no GPU, no game files, on current main (895c472fa) plus this branch:

  • python -I tests/test_x64_recomp.py: 51 tests, OK (34 skipped: no qemu-system-aarch64).
  • Red: the same tests with main's tools/x64_recomp.py: 1 failure (test_never_reads_past_end) and 1 error (test_truncated_vex_and_evex_are_decode_errors).
  • python -I tests/test_recomp_census.py: 13 tests OK; it errors with main's tool.
  • python -I scripts/check_no_game_data.py on the three changed files: clean.
  • Not run: the full suite, CI.

GPUs tested: n/a (decoder unit tests only)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md).
  • A new translator rule is in the contract table of docs/design.md. (n/a: x64 decoder bounds fix, no translator rule)

Supersedes #1121 once merged; the original stays open until a maintainer decides.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5604874582 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3101). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T10:48:17Z. --- Claimed in the coordination issue as: X64-RECOMP-VEX-BOUNDS (the claim of the original author, https://github.com/ProjectLeonida/mandy/issues/14#issuecomment-7140338734) Depends on: #1120 (merged) ### What and why Carry of #1121 (kett1m), in conflict with `main` since `tests/test_x64_recomp.py` changed on both sides. This branch is `main` merged with the head of #1121 (`72eedf158`), so the author's commits are kept. My only change is the merge: main's tests and the PR's two new tests both stay. The change itself is #1121's: `decode_one` promises never to read past `end`, but a buffer ending inside a two- or three-byte VEX prefix or an EVEX prefix indexed one byte past it and raised `IndexError`, which callers that only catch `DecodeError` (`tools/recomp_census.py`) did not survive. It now raises `DecodeError`. `test_truncated_vex_and_evex_are_decode_errors` pins the four truncated forms and `test_never_reads_past_end` checks every sequence up to four bytes of a prefix/opcode alphabet. ### Tested Windows 11, no GPU, no game files, on current `main` (`895c472fa`) plus this branch: - `python -I tests/test_x64_recomp.py`: 51 tests, OK (34 skipped: no `qemu-system-aarch64`). - Red: the same tests with main's `tools/x64_recomp.py`: 1 failure (`test_never_reads_past_end`) and 1 error (`test_truncated_vex_and_evex_are_decode_errors`). - `python -I tests/test_recomp_census.py`: 13 tests OK; it errors with main's tool. - `python -I scripts/check_no_game_data.py` on the three changed files: clean. - Not run: the full suite, CI. GPUs tested: n/a (decoder unit tests only) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md). - [ ] A new translator rule is in the contract table of `docs/design.md`. (n/a: x64 decoder bounds fix, no translator rule) Supersedes #1121 once merged; the original stays open until a maintainer decides. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
enlight3d commented 2026-12-02 11:07:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T11:07:06Z.


RUN (independent run on Windows, #3101 head 6d918ef46, merged locally into main 895c472fa with git merge --no-ff, no conflicts. The result's tree is the head's tree. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)

  • History: 6d918ef46 is a two-parent merge of main and #1121's head 72eedf158, so kett1m's commits 84239b50b and 72eedf158 are ancestors of the head under their own name (git merge-base --is-ancestor says yes).
  • Conflict: I merged 72eedf158 into main again myself. Git stops on tests/test_x64_recomp.py only. The head's version is a keep-both-sides resolution (git merge-file --union from the three index stages), apart from one blank line. tools/x64_recomp.py and tests/test_recomp_census.py are byte-identical to git's own auto-merge.
  • python -I tests/test_x64_recomp.py -v: main 49 tests OK (34 skipped, qemu-system-aarch64 not installed); merge 51 tests OK (the same 34 skipped). The two new tests are decoder-only and ran.
  • python -I tests/test_recomp_census.py -v: main 12 tests OK; merge 13 tests OK.
  • python -m pytest on the 23 test files that name x64_recomp or recomp_census: main 100 passed / 103 skipped; merge 103 passed / 103 skipped.
  • Red: main's tools/x64_recomp.py with this pull request's test files.
    • test_x64_recomp.py: 51 tests, 1 failure and 1 error, as the body says. test_truncated_vex_and_evex_are_decode_errors errors with IndexError. test_never_reads_past_end fails with "decode_one read past end on c462".
    • test_recomp_census.py: 13 tests, 1 error. test_truncated_vex_prefix_is_a_gap_not_a_crash raises IndexError out of census(), so one truncated function aborts the whole census.
  • Mutations of the merge's tools/x64_recomp.py, each run with both test files and restored afterwards (git status clean). The first six are killed:
    • EVEX check after the prefix removed: killed (test_x64_recomp.py: 1 failure, 1 error).
    • Three-byte VEX payload check (pos + 2 >= end) removed: killed (same).
    • Check after the VEX prefix (pos >= end before the opcode read) removed: killed in both files, including the census test.
    • Each of the three checks made off by one (> in place of >=): killed. The VEX opcode one is also killed by the census test.
    • The three checks compared with len(buf) in place of end: survives both files (51 OK, 13 OK). In the four truncated forms of the new test and in the exhaustive test, the buffer ends at end, so end and len(buf) agree.
  • Probe with the four truncated forms followed by more bytes (c3 90 90 90), end still at the end of the prefix:
    • main decodes c4 68 as an instruction of size 4 with end = 2, and does the same for c4 68 c3 and 62 f1 7c 48, so it reads past end without any error.
    • The merge raises DecodeError for all four.
    • The len(buf) mutation behaves like main there. The fix itself is right, but the tests pin it only where the buffer stops at end. A padded variant of the four forms would pin end.

Not covered here: Linux and macOS, the 34 qemu-backed tests (no qemu-system-aarch64 on this machine), and real executables (synthetic bytes and a synthetic PE only).

Verdict: PASS. The change does what the body says, red on main and green on the merge match the stated counts, the targeted mutations are killed except the len(buf) one, and kett1m's commits are kept. The only gap is that no test uses a buffer longer than end.

Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests only, no GPU or game files used.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7343449238 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3101#issuecomment-7343449238). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-12-02T11:07:06Z. --- RUN (independent run on Windows, #3101 head 6d918ef46, merged locally into `main` 895c472fa with `git merge --no-ff`, no conflicts. The result's tree is the head's tree. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) - History: 6d918ef46 is a two-parent merge of `main` and #1121's head 72eedf158, so kett1m's commits 84239b50b and 72eedf158 are ancestors of the head under their own name (`git merge-base --is-ancestor` says yes). - Conflict: I merged 72eedf158 into `main` again myself. Git stops on `tests/test_x64_recomp.py` only. The head's version is a keep-both-sides resolution (`git merge-file --union` from the three index stages), apart from one blank line. `tools/x64_recomp.py` and `tests/test_recomp_census.py` are byte-identical to git's own auto-merge. - `python -I tests/test_x64_recomp.py -v`: main 49 tests OK (34 skipped, `qemu-system-aarch64` not installed); merge 51 tests OK (the same 34 skipped). The two new tests are decoder-only and ran. - `python -I tests/test_recomp_census.py -v`: main 12 tests OK; merge 13 tests OK. - `python -m pytest` on the 23 test files that name `x64_recomp` or `recomp_census`: main 100 passed / 103 skipped; merge 103 passed / 103 skipped. - Red: `main`'s `tools/x64_recomp.py` with this pull request's test files. - `test_x64_recomp.py`: 51 tests, 1 failure and 1 error, as the body says. `test_truncated_vex_and_evex_are_decode_errors` errors with `IndexError`. `test_never_reads_past_end` fails with "decode_one read past end on c462". - `test_recomp_census.py`: 13 tests, 1 error. `test_truncated_vex_prefix_is_a_gap_not_a_crash` raises `IndexError` out of `census()`, so one truncated function aborts the whole census. - Mutations of the merge's `tools/x64_recomp.py`, each run with both test files and restored afterwards (`git status` clean). The first six are killed: - EVEX check after the prefix removed: killed (`test_x64_recomp.py`: 1 failure, 1 error). - Three-byte VEX payload check (`pos + 2 >= end`) removed: killed (same). - Check after the VEX prefix (`pos >= end` before the opcode read) removed: killed in both files, including the census test. - Each of the three checks made off by one (`>` in place of `>=`): killed. The VEX opcode one is also killed by the census test. - The three checks compared with `len(buf)` in place of `end`: survives both files (51 OK, 13 OK). In the four truncated forms of the new test and in the exhaustive test, the buffer ends at `end`, so `end` and `len(buf)` agree. - Probe with the four truncated forms followed by more bytes (`c3 90 90 90`), `end` still at the end of the prefix: - `main` decodes `c4 68` as an instruction of size 4 with `end` = 2, and does the same for `c4 68 c3` and `62 f1 7c 48`, so it reads past `end` without any error. - The merge raises `DecodeError` for all four. - The `len(buf)` mutation behaves like `main` there. The fix itself is right, but the tests pin it only where the buffer stops at `end`. A padded variant of the four forms would pin `end`. Not covered here: Linux and macOS, the 34 qemu-backed tests (no `qemu-system-aarch64` on this machine), and real executables (synthetic bytes and a synthetic PE only). Verdict: PASS. The change does what the body says, red on `main` and green on the merge match the stated counts, the targeted mutations are killed except the `len(buf)` one, and kett1m's commits are kept. The only gap is that no test uses a buffer longer than `end`. Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests only, no GPU or game files used.
MoonEyes commented 2026-12-02 11:08:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T11:08:48Z.


Merging. Head 6d918ef46 merges cleanly with main a252854a2 and does not force a rebase of #2566. Independent check on head 6d918ef46: enlight3d's red/green on main 895c472fa + this head (red with main's tool, green 51 and 13 OK, six targeted mutations killed; one len(buf)-for-end mutation survives because no test pads the buffer past end, noted as a gap, not a defect), comment 7343449238; kett1m's commits from #1121 are ancestors; CI 5/5 green incl. no-game-data; no open review or question; item X64-RECOMP-VEX-BOUNDS claimed by kett1m in #14. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7343491052 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3101#issuecomment-7343491052). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T11:08:48Z. --- Merging. Head `6d918ef46` merges cleanly with `main` `a252854a2` and does not force a rebase of #2566. Independent check on head 6d918ef46: enlight3d's red/green on main 895c472fa + this head (red with main's tool, green 51 and 13 OK, six targeted mutations killed; one len(buf)-for-end mutation survives because no test pads the buffer past end, noted as a gap, not a defect), comment 7343449238; kett1m's commits from #1121 are ancestors; CI 5/5 green incl. no-game-data; no open review or question; item X64-RECOMP-VEX-BOUNDS claimed by kett1m in #14. Merged by MoonEyes. AI-assisted (Claude Code).
lixonik commented 2026-12-02 11:14:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T11:14:38Z.


Verified locally on Windows 10 x64, PR head 6d918ef46 merged cleanly onto main a252854a2:

  • Red -> Green proof:
    • With main's tools/x64_recomp.py + the PR's new tests:
      • python -I tests/test_x64_recomp.py -- FAILED (rc=1, failures=1, errors=1, skipped=34).
      • python -I tests/test_recomp_census.py -- FAILED (rc=1, errors=1).
    • With PR #3101 (6d918ef46):
      • python -I tests/test_x64_recomp.py -- PASSED (rc=0, OK (skipped=34)).
      • python -I tests/test_recomp_census.py -- PASSED (rc=0, OK).
  • Clean-room check: python -I scripts/check_no_game_data.py tests/test_recomp_census.py tests/test_x64_recomp.py tools/x64_recomp.py -- exit 0.
  • Code review: cleanly guards post-EVEX (pos >= end), 3-byte VEX payload (pos + 2 >= end), and post-VEX opcode (pos >= end) reads in decode_one() so truncated prefixes raise DecodeError instead of IndexError, matching the exhaustive 1..4-byte boundary test.

Result: PASS.

AI-assisted: yes (Antigravity).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7343634481 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3101#issuecomment-7343634481). Originally posted by [lixonik](https://github.com/lixonik) on 2026-12-02T11:14:38Z. --- Verified locally on Windows 10 x64, PR head `6d918ef46` merged cleanly onto `main` `a252854a2`: - **Red -> Green proof:** - With `main`'s `tools/x64_recomp.py` + the PR's new tests: - `python -I tests/test_x64_recomp.py` -- **FAILED** (`rc=1`, `failures=1, errors=1, skipped=34`). - `python -I tests/test_recomp_census.py` -- **FAILED** (`rc=1`, `errors=1`). - With PR `#3101` (`6d918ef46`): - `python -I tests/test_x64_recomp.py` -- **PASSED** (`rc=0`, `OK (skipped=34)`). - `python -I tests/test_recomp_census.py` -- **PASSED** (`rc=0`, `OK`). - **Clean-room check:** `python -I scripts/check_no_game_data.py tests/test_recomp_census.py tests/test_x64_recomp.py tools/x64_recomp.py` -- exit `0`. - **Code review:** cleanly guards post-EVEX (`pos >= end`), 3-byte VEX payload (`pos + 2 >= end`), and post-VEX opcode (`pos >= end`) reads in `decode_one()` so truncated prefixes raise `DecodeError` instead of `IndexError`, matching the exhaustive 1..4-byte boundary test. Result: **PASS**. AI-assisted: yes (Antigravity).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!3101
No description provided.