GPU: guard alias_source against null resources, unmapped heaps, and empty planes #2865
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!2865
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2865"
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?
@danielibabet on GitHub · 2026-11-25 22:43 UTC · original
danielibabet:fix/alias-source-null-guard→main· +12 −8 · 2 files · 1 commits · closed without mergingProblem
When a shader binds an unbounded or null shader-resource view (
View::Shader(0, ...)),draw::readableinvokedcrate::resource::alias_source(*resource as This)with a null pointer (*resource == 0).Inside
alias_source:placed.cast::<Resource>()dereferencedb.descat offset0x10, which insidebytes(&b.desc)accessedd.layoutat offset0x20(reading0x0 + 0x30), triggering an unhandled Access Violation0xc0000005invictory.exeduring world loading.b.data()was null (an unmapped heap resource), returning a null data pointer could falsely collide and alias another null-data resource inTEXTURES_AT.t.planes[0]could panic if a descriptor had an emptyplanesvector.Closes #2847
Closes #2852
Change
readable: check*resource != 0before queryingalias_source.alias_source: returnNoneimmediately ifplaced.is_null()or ifb.data().is_null().t.planes.first()instead of direct indexingt.planes[0]to safely fail closed.resource::tests::a_null_view_has_no_alias_source.Tested
cargo test -p victory-gpu --lib alias_sourcepasses cleanly.cargo test -p victory-gpuclean.7952987Athrough the world loading transition where the crash previously occurred; runs continuously past the checkpoint without crashing.@kotekompotek on GitHub · 2026-11-25 22:50 UTC · original · reviewed
Not a duplicate of the just-merged null-view guard (
219878acovers placed==0) — this adds two real guards further in: b.data() null means an unmapped heap resource, which could otherwise alias another null-data resource's entry in TEXTURES_AT, and planes.first() fixes a panic path (indexing an empty planes vec) for a desc with no planes. Both fail-closed directions are right. LGTM.@AwsAli05 on GitHub · 2026-11-25 22:55 UTC · original · reviewed
Static review of
a227883against the current null-SRV fix in219878a0.I could not find a valid resource that reaches either new case.
create_placedrejects a null heap and retains the heap reference.create_at_addressrejects address zero, andTexture::newalways constructs its first plane before returningOk. An uncommitted range can still have a nonzero virtual address, so checkingb.data().is_null()does not detect that case.Can you identify the resource construction path that produced the remaining failure and cover it with a regression test? The existing null-SRV fix already handles the world-load crash (#2847). A focused test would help establish what additional runtime failure this PR fixes.
AI-assisted static review.
@danielibabet on GitHub · 2026-11-25 22:59 UTC · original
Indeed, commit
219878a0covers the immediate null-SRV dispatch crash fromView::Shader(0, ...). The primary goal here (as also noted by @kotekompotek) is defense-in-depth and fail-closed safety around raw FFI pointers in the GPU subsystem:draw.rs, guarding*resource != 0avoids queryingalias_sourceentirely for null shader views.Resource::data(),heapis held as an untyped raw pointer (*mut c_void); validatingh.is_null()prevents undefined dereferences inunsafeblocks.alias_source, guardingb.data().is_null()ensures that unbacked resources cannot falsely match and alias another null-addressed entry under key0inTEXTURES_AT.t.planes.first()eliminates a potential panic path (indexingt.planes[0]) in case of empty-plane descriptors.It introduces zero runtime overhead while hardening
alias_sourceagainst edge-case memory safety regressions.@fuzeofficlal on GitHub · 2026-11-25 23:44 UTC · original · reviewed
Verified head
a2278834cleanly merged ontoorigin/main(63bcca43, post-219878a0) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP +VICTORY_D3D12_DEBUG=1).Code Review
crates/victory-gpu/src/resource.rs:1802:t.planes.first().map_or(d.layout, ...)removes an out-of-bounds panic risk ifplanesis empty.crates/victory-gpu/src/resource.rs:1807-1810: returningNonewhenb.data().is_null()prevents aBacking::Address(0)resource from queryingTEXTURES_ATat address0.crates/victory-gpu/src/draw.rs:1894: early-outing on*resource != 0avoids callingalias_sourceon null SRVs (redundant for safety after219878a0, but saves the lookup).if h.is_null()check inResource::data()(resource.rs:1497-1501) is unreachable today becausecreate_placed(resource.rs:2101) already rejects a null heap withE_INVALIDARGandBacking::drop(resource.rs:767) assumes it is non-null.planes.is_empty()/ null-addressalias_sourcewould lock in the remaining non-219878a0guards.Local Verification (
VICTORY_D3D12_DEBUG=1)resource::tests18/18,draw::tests20/20.cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics) &cargo xtask policy(191 files ok): clean.@futurepro62 on GitHub · 2026-11-26 00:09 UTC · original
Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head
a227883(on its base219878a).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 864 passed, 0 failed, 10 ignored.#[test]functions in the diff.--skipleaves out tests that fail on main842b0cbon this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
@Marvisak on GitHub · 2026-11-26 04:25 UTC · original
Automated triage for the maintainers.
Proposed close. Already in
main. The crash this guards against, a null shader view reachingalias_source, is fixed in main by219878a("GPU: a null shader view has no alias source"), which returnsNonefor a nullplacedat the top ofalias_sourceincrates/victory-gpu/src/resource.rsand adds a test. The remaining guards cover cases that cannot occur: aBacking::Placedheap is dereferenced and AddRef'd when the resource is placed, so it is never null, and a texture layout always has at least one plane. Turning those into a silent null or fallback would hide a real bug rather than fix one.CI: passing.
This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the
triage: proposed closelabel.Generated by Claude Code
@danielibabet on GitHub · 2026-11-26 07:35 UTC · original
Thanks for the clarification and review @Marvisak, @fuzeofficlal, and @kotekompotek! Completely understand the preference for loud failures over silent fallbacks on internal invariants. Glad to see
219878aalready resolved the root crash in main. Closing!Pull request closed