D3D12.X: read unaligned UTF-16 and qwords via byte slices in guard::describe_ptr #1584
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1594"
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 ivall/xcl. Originally posted by b3IKK on 2026-11-24T18:03:36Z.
guard::describe_ptrincrates/xcl/src/hle/d3d12x/guard.rspreviously created&[u16]and&[u64]viastd::slice::from_raw_partsdirectly from an arbitrary guest registerpwithout checking 2-byte or 8-byte alignment, which is immediate UB (and a debug-mode panic in Rust) whenever a pointer argument is unaligned.Moreover, calling
std::slice::from_raw_partsdirectly over foreign guest memory afterreadable()only proves virtual pages are committed, not thatp..p+spanbelongs to a single Rust allocation or won't race a concurrent decommit.This copies the target bytes into a local stack buffer
[0u8; 128]viaReadProcessMemory(GetCurrentProcess(), ...)and decodes UTF-16 code units andu64words withfrom_le_bytes, eliminating both alignment UB and foreign-memory slice UB.What is in it
crates/xcl/src/hle/d3d12x/guard.rs: copy up to 128 bytes viaReadProcessMemoryinto a local[0u8; 128]buffer and parse UTF-16 /u64words viafrom_le_bytes; add unit testdescribe_ptr_handles_unaligned_utf16_and_binary_pointers(failed before the fix withunsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware; 1no heap windows—heap_window_out_of_memory_falls_back_to_the_switch_form)cargo test -p xcl --lib guard::tests: 1 passed, 0 failedRegression run
main:
PR:
Not tested
AI use
hle/d3d12x/guard.rs, wrote the fix and unit test, switched toReadProcessMemoryinto a local stack buffer per review feedback, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:07:28Z.
Review: COMMENTED
AI-assisted review (GPT-6): I checked the
readableimplementation and traced the slice bounds in the new test.Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:07:29Z.
Code review location:
crates/xcl/src/hle/d3d12x/guard.rs; line 95readableonly proves that the virtual pages are committed and readable; it cannot prove thatp..p+spanbelongs to one Rust allocation. Forming a 128-byte slice here can therefore be undefined behavior for a valid game pointer near an allocation boundary. The new test passes a pointer into a 64-byte array, which makes this mismatch concrete if the surrounding stack page is readable. Please bound the read to caller-known storage or copy via a bounded raw-read mechanism before forming a slice. AI-assisted review: I verified this againstreadableand the new test.Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T18:39:29Z.
Good catch @gut0to — updated in \
6ea563b\ to copy into a local [0u8; 128]\ buffer via \ReadProcessMemory(GetCurrentProcess(), ...)\ instead of calling \slice::from_raw_parts\ over arbitrary foreign memory, and enlarged the test's backing array to 256 bytes. Re-ran \scripts/test.ps1\ and the 60 s \scripts/smoke.ps1\ run.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T18:56:54Z.
Full-suite run, since this PR has no test report yet. Tested exact head
6ea563b(on its base9e3831e).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 776 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.describe_ptr_handles_unaligned_utf16_and_binary_pointers.f940362(the PR was updated before the NVIDIA run above) on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2,XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 777 passed, 0 failed, 41 ignored. SKIPPED:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).heap_window_out_of_memory_falls_back_to_the_switch_formwas skipped with--skip. It fails on main9e3831etoo, not because of this PR: underXCL_REQUIRE_GPU=mesh,runner::skip_testturns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWSunset). Reported as #1651.Not tested
AI use
upstream-sync referenced this pull request2026-11-24 21:07:02 +00:00
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T20:12:13Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
upstream-sync referenced this pull request2026-11-24 23:06:49 +00:00
Imported from ivall/xcl. Originally posted by afpruivo on 2026-11-26T12:18:20Z.
Tested
6ea563bon an RTX 3090, as part of a batch merged ontomainb49be18: no failures, no regression.e15ddb2, #15946ea563b, #162139788e8, #165369f70c1. They touch no common file and merged cleanly ontob49be18(local commit1e3fb07). Check posted in #1607: B21, https://github.com/xcl-dev/xcl/issues/1607#issuecomment-7191828681.cargo test --workspace -- --test-threads=4(debug): 1,439 passed, 0 failed, 47 ignored. 26SKIPPEDGPU tests, mostly no wave64 on this card; they are not coverage.scripts/smoke.ps1, 60 s, retail 1.0.2.1 (title: 3c290c16), release. Peak commit was lower on the batch.mainb49be181e3fb07readablechecks stay before the copy, and all three outputs (UTF-16, ASCII, the four qwords) now read only from the local 128-byte buffer.Not tested: a run that reaches this change on purpose (the smoke title only shows that nothing regresses); AMD.
AI use: Claude Code (Claude Opus 5.5) ran the commands on my machine and drafted this. Checked by me before posting.
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:34:16Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:13:02Z.
Triage (#1607) – head
6ea563bNo open or merged PR changes
guard::describe_ptr; main still reads through*(p as *const u16)/*(p as *const u64), which is UB on an unaligned argument (debug builds panic on the misaligned dereference). #3139 callsdescribe_ptrfrom a new probe but does not change it.The fix reads up to 128 bytes with
ReadProcessMemoryinto a local buffer and decodes from it. The title says "byte slices", but the change is a copy through ReadProcessMemory. The test covers an odd-address UTF-16 string and odd-address qwords.The PR conflicts with main and needs a rebase.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.