x64_recomp: a buffer that ends inside a VEX/EVEX prefix is a DecodeError (X64-RECOMP-VEX-BOUNDS, carry of #1121) #3101
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3101"
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 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
mainsincetests/test_x64_recomp.pychanged on both sides. This branch ismainmerged 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_onepromises never to read pastend, but a buffer ending inside a two- or three-byte VEX prefix or an EVEX prefix indexed one byte past it and raisedIndexError, which callers that only catchDecodeError(tools/recomp_census.py) did not survive. It now raisesDecodeError.test_truncated_vex_and_evex_are_decode_errorspins the four truncated forms andtest_never_reads_past_endchecks 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: noqemu-system-aarch64).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.pyon the three changed files: clean.GPUs tested: n/a (decoder unit tests only)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly.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
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T11:07:06Z.
RUN (independent run on Windows, #3101 head
6d918ef46, merged locally intomain895c472fawithgit 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.)6d918ef46is a two-parent merge ofmainand #1121's head72eedf158, so kett1m's commits84239b50band72eedf158are ancestors of the head under their own name (git merge-base --is-ancestorsays yes).72eedf158intomainagain myself. Git stops ontests/test_x64_recomp.pyonly. The head's version is a keep-both-sides resolution (git merge-file --unionfrom the three index stages), apart from one blank line.tools/x64_recomp.pyandtests/test_recomp_census.pyare byte-identical to git's own auto-merge.python -I tests/test_x64_recomp.py -v: main 49 tests OK (34 skipped,qemu-system-aarch64not 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 pyteston the 23 test files that namex64_recomporrecomp_census: main 100 passed / 103 skipped; merge 103 passed / 103 skipped.main'stools/x64_recomp.pywith 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_errorserrors withIndexError.test_never_reads_past_endfails 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_crashraisesIndexErrorout ofcensus(), so one truncated function aborts the whole census.tools/x64_recomp.py, each run with both test files and restored afterwards (git statusclean). The first six are killed:test_x64_recomp.py: 1 failure, 1 error).pos + 2 >= end) removed: killed (same).pos >= endbefore the opcode read) removed: killed in both files, including the census test.>in place of>=): killed. The VEX opcode one is also killed by the census test.len(buf)in place ofend: survives both files (51 OK, 13 OK). In the four truncated forms of the new test and in the exhaustive test, the buffer ends atend, soendandlen(buf)agree.c3 90 90 90),endstill at the end of the prefix:maindecodesc4 68as an instruction of size 4 withend= 2, and does the same forc4 68 c3and62 f1 7c 48, so it reads pastendwithout any error.DecodeErrorfor all four.len(buf)mutation behaves likemainthere. The fix itself is right, but the tests pin it only where the buffer stops atend. A padded variant of the four forms would pinend.Not covered here: Linux and macOS, the 34 qemu-backed tests (no
qemu-system-aarch64on this machine), and real executables (synthetic bytes and a synthetic PE only).Verdict: PASS. The change does what the body says, red on
mainand green on the merge match the stated counts, the targeted mutations are killed except thelen(buf)one, and kett1m's commits are kept. The only gap is that no test uses a buffer longer thanend.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.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T11:08:48Z.
Merging. Head
6d918ef46merges cleanly withmaina252854a2and does not force a rebase of #2566. Independent check on head6d918ef46: enlight3d's red/green on main895c472fa+ 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).
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T11:14:38Z.
Verified locally on Windows 10 x64, PR head
6d918ef46merged cleanly ontomaina252854a2:main'stools/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).#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).python -I scripts/check_no_game_data.py tests/test_recomp_census.py tests/test_x64_recomp.py tools/x64_recomp.py-- exit0.pos >= end), 3-byte VEX payload (pos + 2 >= end), and post-VEX opcode (pos >= end) reads indecode_one()so truncated prefixes raiseDecodeErrorinstead ofIndexError, matching the exhaustive 1..4-byte boundary test.Result: PASS.
AI-assisted: yes (Antigravity).