GPU: saturate COM AddRef against u32 wrap and add unit tests for object.rs #931
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#931
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?
@geiyiliyabumo on GitHub · 2026-11-24 14:18 UTC · original
Summary
Fixes a COM reference-count wrap bug in
crates/victory-gpu/src/object.rs(add_refusingfetch_addcould wrapu32::MAX -> 0) and adds 17 deterministic synthetic unit tests (18 total inobject.rs, previously 0).Because external PR creation is currently restricted (
collaborators_only), the CI-green branch is ready on my fork for cherry-pick / review:geiyiliyabumo/VIctory@test/gpu-object-testsgeiyiliyabumo/VIctory@b82fb12(based onmainffe310e)Changes (
crates/victory-gpu/src/object.rs)add_refnow saturates atu32::MAXviafetch_update+checked_add, preserving the COM invariant thatAddRefnever wraps to0.AddRefsaturation,Releaseunderflow floor, last-ref free & private-data cleanup,hand_outaccept/reject/null-out drop paths,answerresult clearing/refcount, IID matching (incl. null),GetPrivateData/SetPrivateData,SetName,d3d12_objectvtable slots, andparent_device.Verification (Windows 11 x64 MSVC)
rustfmt --edition 2024 --check crates/victory-gpu/src/object.rs: PASScargo xtask policy: PASS (154 files ok)cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default +--features diagnostics): PASS (0 warnings)cargo test -p victory-gpu --locked -- object::: 18 passed, 0 failedAI-assisted; synthetic tests only, no game files.
@DaniiL35 on GitHub · 2026-11-24 14:41 UTC · original
Independent Verification Review: geiyiliyabumo:test/gpu-object-tests (
b82fb12)Audited the COM reference-count saturation logic and object vtable tests in
crates/victory-gpu/src/object.rs:1. COM Lifetime Symmetry & Saturation Invariant
release(line 77), reference decrements were already floored at zero usingfetch_update(..., |n| n.checked_sub(1)).add_ref(line 71), previous code performed an unconstrainedfetch_add(1). If refcounts wrappedu32::MAX -> 0, the object appeared zero-referenced and became vulnerable to premature drop or resource reclamation while active callers held references.n == u32::MAX,checked_add(1)returnsNone, preservingu32::MAXin the atomic without wrapping, andcurrent.saturating_add(1)returnsu32::MAX. This mirrors the standard COM lifetime convention thatAddRefnever wraps to 0.2. Test Suite & Cross-Platform Execution
object.rstest coverage from 0 to 18 unit tests.Trackedwrapper withRc<Cell<usize>>to verify destruction timing and prevent memory leaks.AddRefsaturation,Releasefloor at zero, private-data cleanup on drop,hand_outdrop safety on null pointers, and vtable slot offset alignments.object.rscontains zero Windows D3D12 host device dependencies, all 18 tests run cleanly across non-Windows environments (macOS / Linux) as part ofcargo test -p victory-gpu.Ready to merge cleanly onto
main.@NethminaYasas on GitHub · 2026-11-24 15:31 UTC · original
Claiming this one: I'll mirror
elease's \checked_sub\ with a saturating \AddRef\ in \crates/victory-gpu/src/object.rs\ and add a focused unit test that sets the refcount to \u32::MAX, then open a PR. I saw the independent verification review of \geiyiliyabumo:test/gpu-object-tests\ above — if that branch is about to become an upstream PR, please say so and I'll defer to it. This work is AI-assisted (OpenCode) and uses no game data.
@adamdotpy on GitHub · 2026-11-24 15:44 UTC · original
Carried to #1100 with @geiyiliyabumo's commit
b82fb12unchanged and its authorship kept.Checked here on
ffe310e(Windows 11, Rust 1.98.1):cargo test -p victory-gpu67 passed / 1 ignored (50 before), clippy clean with--all-features,cargo build --release -p victorybuilds.Red/green on the fix: putting the old
fetch_add(1) + 1back failsadd_ref_saturates_instead_of_wrapping— as an overflow panic in a debug test run, and by wrapping the count to 0 in a release build, which is the real failure the issue describes.One thing to keep in mind if the tests are extended:
UNREFERENCEDandSATURATEDarestaticobjects, one per test, so they do not race today, but a second test on either static would need to serialise against the first.@NethminaYasas on GitHub · 2026-11-24 15:47 UTC · original
Opened PR #1105 with the saturating \AddRef\ and the two synthetic unit tests.
@Marvisak on GitHub · 2026-11-25 06:59 UTC · original
Automated triage for the maintainers.
Confirmed on
main:add_refincrates/victory-gpu/src/object.rsisrefs.fetch_add(1) + 1, so the count wraps pastu32::MAX(and panics in a debug build), whilereleasealready stops at zero. It needs four billion outstanding references to matter. Open PR #2059 (fuzeofficlal) carries the saturating form; the earlier carries #1100 and #1105 were closed unmerged.Generated by Claude Code