Repository navigation
Conversation
…md_only and sse4a
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified against origin/main (940d32f):
- Clamping VEH instruction reads to the faulting page in
emulate_amd_onlyandsse4acleanly prevents secondary page faults at page boundaries. cargo test -p victory-loader crash::tests: 24/24 passed (includingud_instructions_at_page_end_do_not_read_past_page).cargo clippy -p victory-loader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-loader --locked on macOS arm64 — the 3 failures are exactly the known pre-existing macOS prepare::tests (host Mach-O parsed as PE, identical on main; #2334's cfg-gating covers this class). Approving — VEH instruction reads clamped to the faulting page.
|
Independent local validation (Windows, Rust 1.100.0/MSVC, head 609daf4, no game data): |
|
Automated triage for the maintainers. Merge candidate. In Generated by Claude Code |
|
Mechanics are right — copying a page-bounded window up front removes the read-past-page fault inside the VEH itself (the old 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. |
…ing page in emulate_amd_only and sse4a
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed and verified against main (63bcca43) on Windows 11 — clean safety fix and ready to merge:
- Clamping the VEH instruction copy to
room = 0x1000 - (context.Rip as usize & 0xfff)(room.min(32)) before decoding and switchingsse4ato safe slice indexing (&[u8]) eliminates the secondaryACCESS_VIOLATIONwhen a#UDsits at the end of a mapped page next to an unmapped/no-access page.
Local verification:
cargo test --locked -p victory-loader: 40/40 passed (36unit includingud_instructions_at_page_end_do_not_read_past_page+crash_log+load_probe+title_dlls)cargo clippy --all-targets -- -D warnings+cargo xtask policy(191 files ok): 0 warnings
…ing page in emulate_amd_only and sse4a
Problem
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).