You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(hle/dstorage): retain Instance<File> for queued reads and fix WALLS_FILES/factory leaks (#319) - #338
Fixes both the queued Instance<File> use-after-free and the WALLS_FILES / factory resource leaks in crates/victory-hle/src/modules/dstorage.rs tracked in #319.
Prevent Instance<File> use-after-free in queued/in-flight reads:
Added release_file(this: *mut Instance<File>) -> u32 (wired into FILE_VTABLE slot 2) and RAII struct FileRef(*mut Instance<File>) whose retain(request) increments the COM refcount (add_ref_instance) when request.options & MEMORY_SOURCE == 0 && !request.source.is_null() and whose Drop calls release_file.
Added _file: Option<FileRef> to Read (removing Clone, Copy) and Job, retained in enqueue_request, moved from Read to Job in Lanes::start, and automatically released on job completion or queue close_lane.
Changed WALLS_FILES from Mutex<Vec<(usize, String)>> to Mutex<Option<HashMap<usize, String>>>.
Only inserts into WALLS_FILES when walls_trace() > 0, and removes the entry in release_file when refs hits 0 before freeing Box::from_raw(this).
Prevent factory resource leaks on null out:
Added if out.is_null() { return E_POINTER; } at the entry of open_file, create_status_array, and create_queue before opening file handles, allocating Instances, creating Win32 CreateEventW handles, or inserting Lanes.
Unit tests:
Added factory_rejects_null_out_with_e_pointer and queued_read_retains_file_refcount_until_dropped.
Rig Specs Tested On
CPU: Linux workstation (x86_64)
GPU & VRAM: N/A (Windows-only victory-hle crate; full clippy & tests verified on GitHub Actions windows-latest CI)
System RAM: N/A
OS & GPU Driver: Linux (x86_64) — Windows x86_64-pc-windows-msvc CI verifies compilation, clippy, and unit tests
Run Settings & Profile
Build & Commit SHA: rebased on origin/main (b0842d9)
CI run 46891843287 failed to compile victory-hle due to a type-name collision in crates/victory-hle/src/modules/dstorage.rs:
dstorage.rs:126: newly added struct FileRef(*mut Instance<File>); collides with existing type FileRef = *const Instance<File>; at dstorage.rs:529 (E0428, causing E0599 / E0614 at 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_file removing from WALLS_FILES, walls_trace() > 0 gate, out.is_null() -> E_POINTER guards, and queued-read refcount retention + tests) looks solid — once renamed and CI is green, this is ready to merge!
Automated triage for the maintainers (not an approval).
Verdict:needs-work · CI (check):failing
Review Summary
The overall approach for #319 (retaining Instance<File> across queued/in-flight reads, cleaning up WALLS_FILES on final release, and rejecting null out pointers in the factory methods before allocating resources) is sound, but CI is currently failing due to a compile error in crates/victory-hle/src/modules/dstorage.rs, and there is one unsafe edge case in FileRef::retain.
origin/main already defines type FileRef = *const Instance<File>; at line 478 (used by file_close at line 483 and file_get_file_information at line 487).
This PR adds struct FileRef(*mut Instance<File>); in the same module scope, which causes error[E0428]: the name 'FileRef' is defined multiple times on x86_64-pc-windows-msvc CI.
Rename the new RAII guard (e.g., OwnedFileRef or RetainedFile) so it does not collide with the existing FileRef type alias.
Unsafe cast in FileRef::retain when physical-page source (bit 23) is set (crates/victory-hle/src/modules/dstorage.rs)
FileRef::retain currently checks request.options & MEMORY_SOURCE != 0 || request.source.is_null(), then casts request.source to *mut Instance<File> and calls add_ref_instance(file).
Per the Request options comment in dstorage.rs (lines 1260–1261), bit 23 selects a source in physical pages rather than an Instance<File> pointer (and is rejected later during execution). If a request arrives with bit 23 set, retain would perform an atomic increment on a non-Instance<File> pointer and later call release_file on it.
Guard against bit 23 (e.g., const PAGE_SOURCE: u64 = 1 << 23; and return None when request.options & (MEMORY_SOURCE | PAGE_SOURCE) != 0).
To change the verdict:
Rename the new struct FileRef (e.g., to OwnedFileRef) to resolve the E0428 collision with type FileRef at crates/victory-hle/src/modules/dstorage.rs:478.
Guard retain against physical-page source requests (1 << 23) in addition to MEMORY_SOURCE and null source.
Ensure Windows CI (clippy and victory-hle unit tests) passes cleanly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
area: runtimeHLE, threading, lifecycle, or OS runtimetriage: needs workTriage found bugs, missing tests, or requested changes
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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)