GPU: saturate COM AddRef at u32::MAX instead of wrapping #2057
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2059"
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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T04:17:01Z.
Closes #931.
Summary
object::add_refto incrementrefsviafetch_update+checked_add(1)so COM reference counts saturate atu32::MAXinstead of wrapping to0in release builds (which could allow a subsequentReleaseto drop a still-referenced object), matching the existing CAS floor inobject::releaseandobject::release_boxed.Testing
object::tests::add_ref_saturates_at_u32_max_without_wrappingcovering both heap-allocated (hand_out+release_boxed) and static (Object+release) COM objects acrossu32::MAX - 1 -> u32::MAXsaturation, decrement without premature drop, and final1 -> 0destruction.cargo test -p victory-gpu(debug & release),cargo clippy --workspace --all-targets --all-features -- -D warnings, andcargo xtask policy.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:17:34Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
COM AddRef saturates at u32::MAX instead of wrapping — refcount-overflow hardening; classic COM bug class, good.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:44:48Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib object::— 5 passed, 0 failed (1 ignored), includingadd_ref_saturates_at_u32_max_without_wrappingcargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean saturation of COM
AddRefatu32::MAXpreventing reference-count wraparound. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:21:13Z.
Triage verdict — Keep the overflow fix, define ownership at saturation (
37e69e7)Evidence
Checks and limits
Next step
This verification was AI-assisted.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T04:41:39Z.
Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at
37e69e7.victory-gpu: 142 passed, 2 failed, 2 ignored; the newadd_ref_saturates_at_u32_max_without_wrappingpasses. The 2 failures are #1744's heap-cap failures onmain. Same asmainon this hardware. Not run: a title.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T05:00:07Z.
Updated in
57535164— thanks @jeremygold02. Saturation atu32::MAXis now sticky across bothobject::releaseandobject::release_boxed((n != u32::MAX).then(|| n.checked_sub(1)).flatten()), so interface queries orAddRefcalls atu32::MAXcannot be balanced down by laterReleasecalls to drop a still-referenced object. Expanded the unit test to verify normal decrement atu32::MAX - 1, sticky saturation acrossanswer+Releaseatu32::MAX, and ordinary1 -> 0destruction.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:24:14Z.
Automated triage for the maintainers.
Proposed close.
object::add_ref,object::releaseandobject::release_boxed(crates/victory-gpu/src/object.rs) now stop the reference count atu32::MAXand then never drop the object. The count can only get there if a title holds about 4.29 billion references to one object at the same time. A title does not do that, so this is a guard for a case that cannot occur.The guard also has a cost. Real COM lets the count wrap, so this differs from it. An object that did reach the limit would leak for good. The new test must free the saturated box by hand, which also skips the cleanup of the interface map in
release_boxed. The same idea is already open in #1100 and #1105.This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. A reproduction showing a title, or a VIctory code path, that actually reaches this count would change the verdict.
CI: passing (
check).Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T10:17:54Z.
Agreed with the triage analysis —
u32::MAXsimultaneous live references cannot occur in practice and pinning the count diverges from COM cleanup. Closing.Pull request closed