HLE: leave a released-out COM count at zero #31
No reviewers
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!31
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/31/head"
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?
@AndyLatimer on GitHub · 2026-11-23 23:27 UTC · original
AndyLatimer:fix/hle-com-release-underflow→main· +101 −12 · 5 files · 2 commits · closed without mergingIn
dstorage,gameinput,mediaandxg,Releasecomputed the new COM reference count asrefs.fetch_sub(1, Ordering::AcqRel) - 1. When the count is already 0, that subtraction underflowsu32: a panic in debug builds, and in release builds a wrapped count with a second free on the next call that reaches 0.This adds a shared
release_refhelper incrates/victory-hle/src/modules/mod.rs, built onfetch_update+checked_sub(1). At a count of 0 it leaves the count at 0, logs a warning and returnsNone, and the caller frees nothing.Scope (thanks to the review): these objects are freed in the call that takes their count to 0. A title that releases once too often therefore makes its next
Releaseread freed memory beforerelease_refruns, and this change does not detect or fix that use-after-free. What it does guarantee is that our own release paths never underflow or double-free on a count of 0. The tests reach that state by setting the count to 0 on a live object. Catching real double releases would need a freed-object marker (or a quarantine for released objects), which is not part of this PR.Testing
main(d2a4bae) in79bb95e. The conflict was two tests added at the end ofdstorage's test module; both are kept.cargo test --workspace: 268 passed, 4 ignored (need external files). This includes 4 regression tests, one per module.cargo clippy -p victory-hle --all-targets: no new warnings (thexmem.rsone is onmain).cargo xtask policy: pass.🤖 Generated with Claude Code
@Sunkiller-qc on GitHub · 2026-11-23 23:46 UTC · original
Thanks for this. One thing to be aware of: in all four modules, when the count reaches 0 the object is freed in the same call, so a title releasing "once too often" makes its next
Releaseread a freed object beforerelease_ref(modules/mod.rs:52) sees anything. The count-at-0 case it guards only exists for an object whose count is 0 but that was never freed, which these constructors don't create (the tests reach it by storing 0 by hand). The change is harmless, but the description may overstate it. If double releases are a real concern, logging them would need a freed-object marker or a quarantine instead. Static review, not built or run.@DaviTostes on GitHub · 2026-11-24 00:08 UTC · original
Tested
b3ecedestacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass (no regression only).cargo test --workspace: 155 passed, 0 failed, 3 ignored; merge with #39 clean.mainis much wider than the COM-count change — it also carries changes invictory-formats(texture.rs,xma.rs),victory-gpu(descriptor/host.rs,draw.rs) andvictory-hle(dstorage.rs,gameinput.rs). If those are not intended, the branch needs rebasing; if they are prerequisites, they should be named in the description.AI-assisted (DeepSeek V4.1 Flash coding agent).
@lordon1a on GitHub · 2026-11-24 00:20 UTC · original
Verified
b3ecede92on Windows 11 (x86_64-pc-windows-gnullvm,rustc 1.100.0, applied cleanly tomain@35b054ec0): pass.cargo xtask policy: 150 files okcargo test -p victory-hle: 85 passed + 1 integration test (no_dll_planting), 0 failed (+4 new COM refcount saturation tests).AI-assisted.
@AndyLatimer on GitHub · 2026-11-24 01:30 UTC · original
Thanks for the reviews. The description now states the scope accurately: this keeps our own release paths from underflowing or double-freeing at a count of 0, but a title's extra Release after the object was freed is still a use-after-free that this does not catch. The branch is merged with current main (
79bb95e, conflict only between two tests added at the end of dstorage's test module); the diff against main is the five HLE files only.cargo test --workspace: 268 passed.@DaviTostes on GitHub · 2026-11-24 01:34 UTC · original
Tested the new head
79bb95e(merge with main) under Wine 11.22 + vkd3d-proton 3.1 (Arch Linux x86_64, AMD RX 9060 XT, RADV 26.3.1), Windows build ofvictory-hle: pass.victory_hle: 89 passed, 1 failed — the failure ismodules::net::tests::only_loopback_is_reachable(Wine lacksWSAConnectByList); with #195 on top the suite is green.No game data used.
Pull request closed