Skip to content

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

Open
mint17 wants to merge 1 commit into
trustno1-coder:mainfrom
mint17:fix/gpu-alias-liveness-heap-evict-stream-ub
Open

mint17 wants to merge 1 commit into
trustno1-coder:mainfrom
mint17:fix/gpu-alias-liveness-heap-evict-stream-ub

Conversation

@mint17

@mint17 mint17 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

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).

…m Bytecode UB

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.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

MystifiedSky added a commit to MystifiedSky/VIctory-NVIDIA-Improved that referenced this pull request Nov 28, 2026
whoalin1 added a commit to whoalin1/victory-altracing-prs that referenced this pull request Nov 28, 2026
…s, evict Memory::heaps, guard stream Bytecode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants