D3D12.X: read unaligned UTF-16 and qwords via byte slices in guard::describe_ptr #1594
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1594
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@b3IKK on GitHub · 2026-11-24 18:03 UTC · original
b3IKK:d3d12x/guard-describe-ptr-unaligned→main· +41 −9 · 1 files · 1 commits · openguard::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.@b3IKK on GitHub · 2026-11-24 18:39 UTC · original
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.@futurepro62 on GitHub · 2026-11-24 18:56 UTC · original
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
@DavidM1911 on GitHub · 2026-11-24 20:12 UTC · original
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!
@gut0to on GitHub · 2026-11-24 18:07 UTC · original
On
crates/xcl/src/hle/d3d12x/guard.rsline 95 (outdated):readableonly 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.github-bot referenced this pull request2026-11-26 06:47:06 +00:00
@gut0to on GitHub · 2026-11-24 18:07 UTC · original · reviewed
AI-assisted review (GPT-6): I checked the
readableimplementation and traced the slice bounds in the new test.@afpruivo on GitHub · 2026-11-26 12:18 UTC · original
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, #1607.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.
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.