fix(hle/dstorage): retain Instance<File> for queued reads and fix WALLS_FILES/factory leaks (#319) #338
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: launcher
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
run report
security: hold
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs gpu test
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/Androtim--MiniVI!338
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-338"
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?
@RUIZ-Enrique-25002136 on GitHub · 2026-12-02 13:28 UTC · original
RUIZ-Enrique-25002136:fix/dstorage-file-uaf-and-leaks→main· +173 −14 · 1 files · 3 commits · merged 2026-12-02 15:03 UTCSummary
Fixes both the queued
Instance<File>use-after-free and theWALLS_FILES/ factory resource leaks incrates/victory-hle/src/modules/dstorage.rstracked in #319.Fixes #319
Changes
Instance<File>use-after-free in queued/in-flight reads:release_file(this: *mut Instance<File>) -> u32(wired intoFILE_VTABLEslot 2) and RAIIstruct FileRef(*mut Instance<File>)whoseretain(request)increments the COM refcount (add_ref_instance) whenrequest.options & MEMORY_SOURCE == 0 && !request.source.is_null()and whoseDropcallsrelease_file._file: Option<FileRef>toRead(removingClone, Copy) andJob, retained inenqueue_request, moved fromReadtoJobinLanes::start, and automatically released on job completion or queueclose_lane.WALLS_FILESunbounded growth & address aliasing:WALLS_FILESfromMutex<Vec<(usize, String)>>toMutex<Option<HashMap<usize, String>>>.WALLS_FILESwhenwalls_trace() > 0, and removes the entry inrelease_filewhenrefshits0before freeingBox::from_raw(this).out:if out.is_null() { return E_POINTER; }at the entry ofopen_file,create_status_array, andcreate_queuebefore opening file handles, allocatingInstances, creating Win32CreateEventWhandles, or insertingLanes.factory_rejects_null_out_with_e_pointerandqueued_read_retains_file_refcount_until_dropped.Rig Specs Tested On
x86_64)victory-hlecrate; full clippy & tests verified on GitHub Actionswindows-latestCI)x86_64) — Windowsx86_64-pc-windows-msvcCI verifies compilation, clippy, and unit testsRun Settings & Profile
origin/main(b0842d9)VICTORY_*Overrides: N/AMeasurements & Verification
cargo clippy --workspace --all-targets --locked -- -D warnings(verified on GitHub Actionswindows-latestCI)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(verified on GitHub Actionswindows-latestCI)cargo test --locked -p xtask-> 8 passed, 0 failedcargo xtask policy->asset policy: 324 files okcargo test --workspace --exclude victory-gpu --exclude victory-shader --locked(verified on GitHub Actionswindows-latestCI)github-bot referenced this pull request2026-12-02 13:35:34 +00:00
@Androtim on GitHub · 2026-12-02 13:34 UTC · original
CI run
46891843287failed to compilevictory-hledue to a type-name collision incrates/victory-hle/src/modules/dstorage.rs:dstorage.rs:126: newly addedstruct FileRef(*mut Instance<File>);collides with existingtype FileRef = *const Instance<File>;atdstorage.rs:529(E0428, causingE0599/E0614at lines 542 and 546).Renaming the RAII guard to e.g.
struct RetainedFile(*mut Instance<File>);should fix all three errors cleanly. The rest of the diff (release_fileremoving fromWALLS_FILES,walls_trace() > 0gate,out.is_null() -> E_POINTERguards, and queued-read refcount retention + tests) looks solid — once renamed and CI is green, this is ready to merge!@Androtim on GitHub · 2026-12-02 14:05 UTC · original · edited 2026-12-02 15:15 UTC
Automated triage for the maintainers (not an approval).
Verdict:
merge-candidate· CI (check):passingReview Summary
Clean, focused fix in
crates/victory-hle/src/modules/dstorage.rsaddressing queuedInstance<File>lifetime safety,WALLS_FILESgrowth/aliasing, and factory null-outleaks (#319). CI is passing.Verified Changes
Instance<File>retention (RetainedFile,release_file,FILE_VTABLE):RetainedFile::retainincrements the COM refcount viaadd_ref_instanceinenqueue_requestfor file-backed requests (skipping null,MEMORY_SOURCE, andPAGE_SOURCEsources), moves ownership fromReadintoJobinLanes::start, and releases viarelease_fileonDrop.Lanes::finish/ErrorRecord::offinishes reading&job.request), queue teardown inclose_lane(unsubmitted.clear()/reads.clear()), and early return whenqueuesees a closed lane or unavailable scheduler.ErrorRecord::ofandwalls_requestare also updated to handlePAGE_SOURCE(1 << 23) without treatingrequest.sourceas anInstance<File>.WALLS_FILESlifecycle (open_file,release_file,walls_request):Mutex<Vec<(usize, String)>>toMutex<Option<HashMap<usize, String>>>, gated bywalls_trace() > 0(OnceLock, so insert/remove gating is consistent).release_fileremoves the address fromWALLS_FILESbeforeBox::from_raw(this), preventing address-reuse aliasing and avoiding lock-order inversion withscheduler.lock().outguards (open_file,create_status_array,create_queue):if out.is_null() { return E_POINTER; }checks run before opening file handles, creatingInstances, creating Win32 events (CreateEventW), or insertingLanes.factory_rejects_null_out_with_e_pointer,queued_read_retains_file_refcount_until_dropped, andretain_ignores_memory_page_and_null_sourcescover the new invariants.Verdict
merge-candidate— CPU-side HLE/COM lifetime and leak fix with passing CI and unit tests; no real-GPU smoke test required. (Independent technical review, not formal maintainer approval.)Generated with Antigravity CLI (
agy).@Androtim on GitHub · 2026-12-02 14:55 UTC · original
Fixed the review/CI issues on this branch:
FileReftoRetainedFileto eliminate theE0428collision withtype FileRef = *const Instance<File>;.PAGE_SOURCE = 1 << 23guard inRetainedFile::retain,ErrorRecord::of, andwalls_requestso physical-page source requests never dereferencerequest.sourceasInstance<File>.retain_ignores_memory_page_and_null_sources.Verified locally:
cargo +1.98.1-x86_64-pc-windows-gnu xtask policy->324 files okcargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle dstorage --locked->34 passed; 0 failed; 1 ignoredcargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings-> passcargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics --locked -- -D warnings-> pass