D3D12.X: is_adopted() does misaligned *const usize dereference on 4-byte-aligned D3D12_HEAP_PROPERTIES return buffer #1130
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#1130
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@towiice on GitHub · 2026-11-24 12:12 UTC · original
Summary
d3d12x::real::is_adopted(crates/xcl/src/hle/d3d12x/real.rs:636) dereferencesobjas*const usizewithoutread_unaligned():this_first(a, b)callsis_adoptedon both arguments of struct-returning device hooks, includingget_custom_heap_properties_x(slot 26, returningD3D12_HEAP_PROPERTIES, which is[u32; 5]— 4-byte aligned, not 8-byte aligned).When a caller invokes
GetCustomHeapPropertieswith a 4-byte-aligned stack buffer (e.g.0x...b3c),*(obj as *const usize)triggers undefined behavior and aborts debug builds with a non-unwinding panic:Suggested Fix
Use
read_unaligned()inis_adopted:(Alternatively, check
(obj as usize) & 7 == 0first, since real COM objects are always 8-byte aligned — a 4-byte-aligned pointer can never be an adopted COM object.)Found while writing host-driver parity tests for
GetCustomHeapProperties(Part of #480) on Windows 11 x64 (rustc 1.100.0,stable-x86_64-pc-windows-gnullvm, NVIDIA GeForce GTX 1650 SUPER).github-bot referenced this issue2026-11-26 04:59:09 +00:00
@hyperland956-lgtm on GitHub · 2026-11-24 13:50 UTC · original
I agree this is a real alignment issue in the current source snapshot.
readable(obj as usize, 8)validates that the eight bytes are mapped, but does not establishalign_of::<usize>().GetCustomHeapPropertiesuses aD3D12_HEAP_PROPERTIESoutput structure with 4-byte alignment. Consequently,this_first()can pass a non-COM return buffer tois_adopted()and trigger an unaligned*const usizedereference.The minimal change is to use
read_unaligned()for the candidate vtable word after the existing null/readability checks.I prefer this over an alignment-only guard because
is_adopted()is a classifier for arbitrary candidate arguments and should not itself have an alignment precondition.Suggested regression test:
Construct a 4-byte-aligned
D3D12_HEAP_PROPERTIESoutput buffer whose address is not divisible by 8. Invoke both C and C++GetCustomHeapPropertiesargument orderings and verify that it is classified as the return buffer without panicking or modifying the object's vtable.Retain the existing adopted-object/vtable test to ensure real COM pointers still classify correctly.
This is a source-level finding. The proposed patch has not yet been built or tested in my environment.