gpu: fix alias liveness check, Memory::heaps drop eviction, and stream Bytecode UB #693

Manually merged
github merged 1 commit from github-bot/gh-693 into main 2026-11-29 08:22:34 +00:00 AGit
Owner

@⁠mint17 on GitHub · 2026-11-28 03:36 UTC · original
mint17:fix/gpu-alias-liveness-heap-evict-stream-ub → main · +312 −26 · 5 files · 1 commits · merged 2026-11-29 08:16 UTC

Addresses three correctness and memory-safety issues in crates/victory-gpu (zero conflict with #646 or #666):

Changes

  1. Alias liveness & refcount overflow hardening (object.rs, resource.rs):
    • Adds object::is_alive(this) (refs.load(Ordering::Acquire) > 0) and updates resource::is_aliased from alias_with(this, |_| ()).is_some() to alias_with(this, crate::object::is_alive).unwrap_or(false) so a dying target with refs == 0 still registered in TARGETS_AT before Resource::drop completes is not treated as an active alias.
    • Hardens object::add_ref_alive with checked_add(1) to prevent u32::MAX wrap-around.
  2. Evict Memory::heaps entry on Heap::drop (adapted from Marvisak#2234 — memory.rs, descriptor.rs):
    • Adds memory::release_heap(key: usize) matching Memory::heaps's HostHeap pointer key and calls it in Drop for Heap strictly after dropping the SHADER_HEAPS write guard.
  3. Unaligned pipeline stream Bytecode read & truncated subobject guard (adapted from Marvisak#2301 — pipeline.rs):
    • Replaces &*desc.stream.add(at + 8).cast::<Bytecode>() with .read_unaligned() and bounds-checks every subobject with saturating_sub / checked_add before reading payload or calling graphics.read.

Verification

  • cargo test --locked -p victory-gpu --lib -- add_ref_alive is_alive alias safety_tests -- --test-threads=1 (6 passed, 0 failed) and --features diagnostics (5 passed, 0 failed):
    • object::tests::add_ref_alive_and_is_alive_check_refcount_bounds
    • resource::tests::an_alias_source_is_held_after_the_title_releases_it (un-gated to #[cfg(windows)] with RAII cleanup)
    • resource::tests::is_aliased_ignores_dying_target_with_zero_refcount
    • descriptor::safety_tests::released_view_heap_evicts_memory_heap_entry (RAII-guarded)
    • pipeline::safety_tests::unaligned_stream_yields_its_shaders & truncated_shader_subobject_does_not_read_past_stream (RAII-guarded)
  • Zero Clippy warnings across all modified files (default and --all-features) and cargo test --locked -p xtask passed (6 passed, 0 failed, including asset policy).
  • Verified with synthetic unit and D3D12 host tests only (no game files).
**@⁠mint17** on GitHub · 2026-11-28 03:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/693) `mint17:fix/gpu-alias-liveness-heap-evict-stream-ub` → `main` · +312 −26 · 5 files · 1 commits · merged 2026-11-29 08:16 UTC Addresses three correctness and memory-safety issues in `crates/victory-gpu` (zero conflict with #646 or #666): ### Changes 1. **Alias liveness & refcount overflow hardening (`object.rs`, `resource.rs`):** - Adds `object::is_alive(this)` (`refs.load(Ordering::Acquire) > 0`) and updates `resource::is_aliased` from `alias_with(this, |_| ()).is_some()` to `alias_with(this, crate::object::is_alive).unwrap_or(false)` so a dying target with `refs == 0` still registered in `TARGETS_AT` before `Resource::drop` completes is not treated as an active alias. - Hardens `object::add_ref_alive` with `checked_add(1)` to prevent `u32::MAX` wrap-around. 2. **Evict `Memory::heaps` entry on `Heap::drop` (adapted from `Marvisak#2234` — `memory.rs`, `descriptor.rs`):** - Adds `memory::release_heap(key: usize)` matching `Memory::heaps`'s `HostHeap` pointer key and calls it in `Drop for Heap` strictly after dropping the `SHADER_HEAPS` write guard. 3. **Unaligned pipeline stream `Bytecode` read & truncated subobject guard (adapted from `Marvisak#2301` — `pipeline.rs`):** - Replaces `&*desc.stream.add(at + 8).cast::<Bytecode>()` with `.read_unaligned()` and bounds-checks every subobject with `saturating_sub` / `checked_add` before reading payload or calling `graphics.read`. ### Verification - `cargo test --locked -p victory-gpu --lib -- add_ref_alive is_alive alias safety_tests -- --test-threads=1` (6 passed, 0 failed) and `--features diagnostics` (5 passed, 0 failed): - `object::tests::add_ref_alive_and_is_alive_check_refcount_bounds` - `resource::tests::an_alias_source_is_held_after_the_title_releases_it` (un-gated to `#[cfg(windows)]` with RAII cleanup) - `resource::tests::is_aliased_ignores_dying_target_with_zero_refcount` - `descriptor::safety_tests::released_view_heap_evicts_memory_heap_entry` (RAII-guarded) - `pipeline::safety_tests::unaligned_stream_yields_its_shaders` & `truncated_shader_subobject_does_not_read_past_stream` (RAII-guarded) - Zero Clippy warnings across all modified files (default and `--all-features`) and `cargo test --locked -p xtask` passed (6 passed, 0 failed, including asset policy). - Verified with synthetic unit and D3D12 host tests only (no game files).
Address three memory-safety and correctness issues in crates/victory-gpu:

- Fix resource::is_aliased to verify target liveness (object::is_alive,
  refs.load(Acquire) > 0) under TARGETS_AT rather than treating dying
  refs == 0 targets as aliased, and harden object::add_ref_alive with
  checked_add(1) overflow protection.
- Evict Memory::heaps entry on Heap::drop (adapted from Marvisak#2234):
  add memory::release_heap keyed by HostHeap pointer address and invoke
  it in Drop for Heap strictly after dropping the SHADER_HEAPS write guard.
- Fix unaligned pipeline stream Bytecode read and guard truncated stream
  subobjects in pipeline::create_stream (adapted from Marvisak#2301) via
  read_unaligned(), saturating_sub, and checked_add bounds checks.
- Add RAII-guarded unit and D3D12 regression tests for all three fixes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 03:37:42 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-28 04:48 UTC · original · approved these changes

LGTM — verified on Windows (RTX 5090):

  • cargo test -p victory-gpu --lib memory:: (2/2), object:: (5/5, including add_ref_alive_and_is_alive_check_refcount_bounds), and pipeline::tests:: (2/2) all passed
  • 0 new compiler warnings in touched files
  • cargo xtask policy passed (294 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-28 04:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/693#pullrequestreview-6095873443) · **approved these changes** LGTM — verified on Windows (RTX 5090): - `cargo test -p victory-gpu --lib memory::` (2/2), `object::` (5/5, including `add_ref_alive_and_is_alive_check_refcount_bounds`), and `pipeline::tests::` (2/2) all passed - 0 new compiler warnings in touched files - `cargo xtask policy` passed (`294 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github manually merged commit 2fbf162719 into main 2026-11-29 08:22:34 +00:00
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/trustno1-coder--VIctory-NVIDIA!693
No description provided.