GPU: guard alias_source against null resources, unmapped heaps, and empty planes #2865

Closed
github-bot wants to merge 1 commit from github-bot/gh-2865 into main AGit
Owner

@⁠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 merging

Problem

When a shader binds an unbounded or null shader-resource view (View::Shader(0, ...)), draw::readable invoked crate::resource::alias_source(*resource as This) with a null pointer (*resource == 0).

Inside alias_source:

  1. placed.cast::<Resource>() dereferenced b.desc at offset 0x10, which inside bytes(&b.desc) accessed d.layout at offset 0x20 (reading 0x0 + 0x30), triggering an unhandled Access Violation 0xc0000005 in victory.exe during world loading.
  2. If b.data() was null (an unmapped heap resource), returning a null data pointer could falsely collide and alias another null-data resource in TEXTURES_AT.
  3. Indexing t.planes[0] could panic if a descriptor had an empty planes vector.

Closes #2847
Closes #2852

Change

  1. Guard readable: check *resource != 0 before querying alias_source.
  2. Guard alias_source: return None immediately if placed.is_null() or if b.data().is_null().
  3. Use t.planes.first() instead of direct indexing t.planes[0] to safely fail closed.
  4. Add regression unit test resource::tests::a_null_view_has_no_alias_source.

Tested

  • Unit test: cargo test -p victory-gpu --lib alias_source passes cleanly.
  • Full workspace tests: cargo test -p victory-gpu clean.
  • In-game: Re-tested on title 7952987A through the world loading transition where the crash previously occurred; runs continuously past the checkpoint without crashing.
**@⁠danielibabet** on GitHub · 2026-11-25 22:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2865) `danielibabet:fix/alias-source-null-guard` → `main` · +12 −8 · 2 files · 1 commits · closed without merging ## Problem When a shader binds an unbounded or null shader-resource view (`View::Shader(0, ...)`), `draw::readable` invoked `crate::resource::alias_source(*resource as This)` with a null pointer (`*resource == 0`). Inside `alias_source`: 1. `placed.cast::<Resource>()` dereferenced `b.desc` at offset `0x10`, which inside `bytes(&b.desc)` accessed `d.layout` at offset `0x20` (reading `0x0 + 0x30`), triggering an unhandled Access Violation `0xc0000005` in `victory.exe` during world loading. 2. If `b.data()` was null (an unmapped heap resource), returning a null data pointer could falsely collide and alias another null-data resource in `TEXTURES_AT`. 3. Indexing `t.planes[0]` could panic if a descriptor had an empty `planes` vector. Closes #2847 Closes #2852 ## Change 1. Guard `readable`: check `*resource != 0` before querying `alias_source`. 2. Guard `alias_source`: return `None` immediately if `placed.is_null()` or if `b.data().is_null()`. 3. Use `t.planes.first()` instead of direct indexing `t.planes[0]` to safely fail closed. 4. Add regression unit test `resource::tests::a_null_view_has_no_alias_source`. ## Tested - Unit test: `cargo test -p victory-gpu --lib alias_source` passes cleanly. - Full workspace tests: `cargo test -p victory-gpu` clean. - In-game: Re-tested on title `7952987A` through the world loading transition where the crash previously occurred; runs continuously past the checkpoint without crashing.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:15 +00:00
github-bot closed this pull request 2026-11-26 07:37:27 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 22:50 UTC · original · reviewed

Not a duplicate of the just-merged null-view guard (219878a covers 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.

**@⁠kotekompotek** on GitHub · 2026-11-25 22:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2865#pullrequestreview-6066059453) · **reviewed** Not a duplicate of the just-merged null-view guard (219878a covers 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.
Author
Owner

@⁠AwsAli05 on GitHub · 2026-11-25 22:55 UTC · original · reviewed

Static review of a227883 against the current null-SRV fix in 219878a0.

I could not find a valid resource that reaches either new case. create_placed rejects a null heap and retains the heap reference. create_at_address rejects address zero, and Texture::new always constructs its first plane before returning Ok. An uncommitted range can still have a nonzero virtual address, so checking b.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.

**@⁠AwsAli05** on GitHub · 2026-11-25 22:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2865#pullrequestreview-6066112427) · **reviewed** Static review of `a227883` against the current null-SRV fix in `219878a0`. I could not find a valid resource that reaches either new case. `create_placed` rejects a null heap and retains the heap reference. `create_at_address` rejects address zero, and `Texture::new` always constructs its first plane before returning `Ok`. An uncommitted range can still have a nonzero virtual address, so checking `b.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.
Author
Owner

@⁠danielibabet on GitHub · 2026-11-25 22:59 UTC · original

Indeed, commit 219878a0 covers the immediate null-SRV dispatch crash from View::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:

  1. In draw.rs, guarding *resource != 0 avoids querying alias_source entirely for null shader views.
  2. In Resource::data(), heap is held as an untyped raw pointer (*mut c_void); validating h.is_null() prevents undefined dereferences in unsafe blocks.
  3. In alias_source, guarding b.data().is_null() ensures that unbacked resources cannot falsely match and alias another null-addressed entry under key 0 in TEXTURES_AT.
  4. t.planes.first() eliminates a potential panic path (indexing t.planes[0]) in case of empty-plane descriptors.

It introduces zero runtime overhead while hardening alias_source against edge-case memory safety regressions.

**@⁠danielibabet** on GitHub · 2026-11-25 22:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2865#issuecomment-7177026036) Indeed, commit `219878a0` covers the immediate null-SRV dispatch crash from `View::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: 1. In `draw.rs`, guarding `*resource != 0` avoids querying `alias_source` entirely for null shader views. 2. In `Resource::data()`, `heap` is held as an untyped raw pointer (`*mut c_void`); validating `h.is_null()` prevents undefined dereferences in `unsafe` blocks. 3. In `alias_source`, guarding `b.data().is_null()` ensures that unbacked resources cannot falsely match and alias another null-addressed entry under key `0` in `TEXTURES_AT`. 4. `t.planes.first()` eliminates a potential panic path (indexing `t.planes[0]`) in case of empty-plane descriptors. It introduces zero runtime overhead while hardening `alias_source` against edge-case memory safety regressions.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:44 UTC · original · reviewed

Verified head a2278834 cleanly merged onto origin/main (63bcca43, post-219878a0) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).

Code Review

  • Useful guards:
    • crates/victory-gpu/src/resource.rs:1802: t.planes.first().map_or(d.layout, ...) removes an out-of-bounds panic risk if planes is empty.
    • crates/victory-gpu/src/resource.rs:1807-1810: returning None when b.data().is_null() prevents a Backing::Address(0) resource from querying TEXTURES_AT at address 0.
    • crates/victory-gpu/src/draw.rs:1894: early-outing on *resource != 0 avoids calling alias_source on null SRVs (redundant for safety after 219878a0, but saves the lookup).
  • Minor notes (non-blocking):
    • The if h.is_null() check in Resource::data() (resource.rs:1497-1501) is unreachable today because create_placed (resource.rs:2101) already rejects a null heap with E_INVALIDARG and Backing::drop (resource.rs:767) assumes it is non-null.
    • Adding a small regression test for planes.is_empty() / null-address alias_source would lock in the remaining non-219878a0 guards.

Local Verification (VICTORY_D3D12_DEBUG=1)

  • RTX 5090 & WARP: resource::tests 18/18, draw::tests 20/20.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics) & cargo xtask policy (191 files ok): clean.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2865#pullrequestreview-6066565636) · **reviewed** Verified head `a2278834` cleanly merged onto `origin/main` (`63bcca43`, post-`219878a0`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + `VICTORY_D3D12_DEBUG=1`). ### Code Review - **Useful guards**: - `crates/victory-gpu/src/resource.rs:1802`: `t.planes.first().map_or(d.layout, ...)` removes an out-of-bounds panic risk if `planes` is empty. - `crates/victory-gpu/src/resource.rs:1807-1810`: returning `None` when `b.data().is_null()` prevents a `Backing::Address(0)` resource from querying `TEXTURES_AT` at address `0`. - `crates/victory-gpu/src/draw.rs:1894`: early-outing on `*resource != 0` avoids calling `alias_source` on null SRVs (redundant for safety after `219878a0`, but saves the lookup). - **Minor notes (non-blocking)**: - The `if h.is_null()` check in `Resource::data()` (`resource.rs:1497-1501`) is unreachable today because `create_placed` (`resource.rs:2101`) already rejects a null heap with `E_INVALIDARG` and `Backing::drop` (`resource.rs:767`) assumes it is non-null. - Adding a small regression test for `planes.is_empty()` / null-address `alias_source` would lock in the remaining non-`219878a0` guards. ### Local Verification (`VICTORY_D3D12_DEBUG=1`) - **RTX 5090 & WARP**: `resource::tests` **18/18**, `draw::tests` **20/20**. - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`191 files ok`): clean.
Author
Owner

@⁠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 base 219878a).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo 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.
  • No new #[test] functions in the diff.
  • --skip leaves out tests that fail on main 842b0cb on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#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_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 00:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2865#issuecomment-7178451913) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `a227883` (on its base `219878a`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo 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**. - No new `#[test]` functions in the diff. - `--skip` leaves out tests that fail on main `842b0cb` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#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_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠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 reaching alias_source, is fixed in main by 219878a ("GPU: a null shader view has no alias source"), which returns None for a null placed at the top of alias_source in crates/victory-gpu/src/resource.rs and adds a test. The remaining guards cover cases that cannot occur: a Backing::Placed heap 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 close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2865#issuecomment-7182585727) <!-- victory-triage v1 head=a227883478f7711ddc6121d5f604d8c41a2f29b5 verdict=proposed-close at=2026-11-26T04:25:34Z --> Automated triage for the maintainers. **Proposed close.** **Already in `main`.** The crash this guards against, a null shader view reaching `alias_source`, is fixed in main by 219878a ("GPU: a null shader view has no alias source"), which returns `None` for a null `placed` at the top of `alias_source` in `crates/victory-gpu/src/resource.rs` and adds a test. The remaining guards cover cases that cannot occur: a `Backing::Placed` heap 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 close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠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 219878a already resolved the root crash in main. Closing!

**@⁠danielibabet** on GitHub · 2026-11-26 07:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2865#issuecomment-7185614718) 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 219878a already resolved the root crash in main. Closing!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2865
No description provided.