Loader: clamp VEH instruction reads to the faulting page in emulate_amd_only and sse4a #2445
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2445
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2445"
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?
@Texbirds on GitHub · 2026-11-25 13:39 UTC · original
Texbirds:fix/loader-crash-veh-page-boundary→main· +91 −27 · 1 files · 1 commits · openProblem
In
crates/victory-loader/src/crash.rs, the vectored exception handler callsemulate_amd_only()onEXCEPTION_ILLEGAL_INSTRUCTION. Onmain:emulate_amd_only()unconditionally creates a 3-byte slicestd::slice::from_raw_parts(rip as *const u8, 3)before matching 3-byte AMD-only opcodes (0F 01 D9,0F 01 F8, etc.).sse4a()takes a raw*const u8and reads up to 6 bytes (*code.add(at + 4)) without checking how many bytes remain in the readable page.If a
#UDoccurs in the last 1–5 bytes of a mapped 4 KiB page followed by an unmapped orPAGE_NOACCESSpage (for exampleud2at page offset0xffe, a 1-byte#UDat0xfff, or a truncated0x66 0x0f 0x78sequence at0xffc), reading past0x1000causes a secondary Access Violation inside the crash handler itself.Change
emulate_amd_only(), clamp the instruction slice length toroom = 0x1000 - (rip as usize & 0xfff)bytes (the remainder of the faulting 4 KiB page, which is known mapped because instruction fetch reachedRip).sse4a()fromunsafe fn(code: *const u8, ...)to safefn(code: &[u8], ...)using checked.get(...)reads for every byte.#UDrather than reading the next page).Test
ud_instructions_at_page_end_do_not_read_past_page(Windows, syntheticVirtualAllocbuffer, no game data):sse4aon empty, 1-byte, and truncated 4-byte slices.PAGE_NOACCESS, places a 1-byte#UDat0xfff,ud2(0f 0b) at0xffe, and a truncated 4-byteextrqat0xffc, and verifiesemulate_amd_onlyreturnsfalsewithout faulting and leavesRipunchanged.extrq xmm0, 8, 4ending at0x1000and verifies it still emulates cleanly (Ripadvances by 6 andxmm0.Lowextracts0x23from0x1234).@cloph-dsp on GitHub · 2026-11-25 15:42 UTC · original
Independent local validation (Windows, Rust 1.100.0/MSVC, head
609daf4, no game data):cargo test --locked -p victory-loader --lib-> 35 tests passed, 0 failed, exit 0;git diff --checkclean. CPU-only regression run; synthetic VEH page-clamp scenario not replayed. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU tests).@Marvisak on GitHub · 2026-11-25 16:02 UTC · original
Automated triage for the maintainers.
Merge candidate. In
crates/victory-loader/src/crash.rs,emulate_amd_onlyandsse4anow read only the bytes left in the current page, the way main already does forclwb. Per the description, an opcode spanning two pages is no longer emulated. CI: passing.Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 16:52 UTC · original
Mechanics are right — copying a page-bounded window up front removes the read-past-page fault inside the VEH itself (the old
[u8; 3]read could fault for a 3-byte instruction ending exactly at a page end when the next page is unmapped).One trade-off worth a comment: a multi-byte instruction starting in the last 1–2 bytes of a page and spanning onto the next (mapped — it did execute) now gets a 2-byte slice, matches nothing, and returns false → unhandled crash where the old code emulated it. Rare (needs an AMD-only opcode at offset ≥ 0xffe), and strictly the safer direction, but it is a real regression edge. If ever hit, the fix is a second page-tolerant read attempt for the opcode only — not needed now.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.