dstorage: retain queued file references and validate null out pointers #577
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!577
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/577/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?
@DenRakEiw on GitHub · 2026-11-24 05:11 UTC · original
fix/dstorage-file-lifetime→main· +189 −21 · 1 files · 1 commits · closed without mergingDefensive COM lifetime hardening for
crates/victory-hle/src/modules/dstorage.rs:QueuedRead): When a request uses a supported file-backed option set (options & !SUPPORTED_OPTIONS == 0 && options & MEMORY_SOURCE == 0 && !source.is_null()),QueuedRead::newtakes a COM reference (add_ref_instance) on theFileobject and releases it when the worker finishes reading (before signaling status completion) or if the queued read is discarded onClose. This defensively enforces standard DirectStorage lifetime guarantees so a title releasing itsIDStorageFilehandle while reads are in flight cannot cause a use-after-free, while guaranteeing unsupported option bits (such as bit 23 / physical-page sources) never treatrequest.sourceas aFileobject.outvalidation:open_file,create_status_array, andcreate_queuereject nulloutpointers up front withE_INVALIDARGbefore allocating handles or scheduler lanes.outrejection without leaks, and unsupported option bits (1 << 23) leavingrequest.sourceuntouched and returningE_NOTIMPL.Verified locally on Windows 11 x64 (Rust 1.98.1 MSVC):
cargo test -p victory-hle --lib dstorage::— 18 passed, 0 failedcargo clippy -p victory-hle --all-targets— 0 warningscargo xtask policy— okAI-assisted (Gemini 4 Neon).
@geiyiliyabumo on GitHub · 2026-11-24 12:17 UTC · original
Independent verification & code review on Windows 11 x64 (merged onto
mainffe310e):Checks Run
cargo xtask policy: PASS (154 files ok)cargo clippy -p victory-hle --all-targets --locked -- -D warnings(default +--features diagnostics): PASS (0 warnings)cargo test -p victory-hle --locked: PASS (97/97unit tests +1/1no_dll_planting, including all16/16dstoragetests)Review Findings
The
QueuedReadRAII ref-counting (including releasing the file outside the scheduler mutex beforelanes.finish()signals the status array) and the upfrontout.is_null()checks inopen_file/create_status_array/create_queuelook solid and cleanly fix the UAF and leak paths.One real safety edge case to tighten before merge:
QueuedRead::newdereferencesrequest.sourceasInstance<File>even for unsupported source option bits (crates/victory-hle/src/modules/dstorage.rs:709-716):QueuedRead::newcallsadd_ref_instance(file)wheneverrequest.options & MEMORY_SOURCE == 0 && !request.source.is_null().execute()(line 843) rejects unsupported option bits withE_NOTIMPL— including bit 23 (physical-pages source, documented at line 691), whererequest.sourcepoints to a page-number array rather than anInstance<File>COM object.main,execute()returnedE_NOTIMPLwithout ever touchingrequest.source. Here,EnqueueRequestnow callsadd_ref_instance(atomic increment at offset+8) onrequest.sourcebeforeexecute()can reject it, which can corrupt caller memory or fault.QueuedRead::newwith the same supported-options mask asexecute()(e.g.request.options & !(ZLIB | BCPACK | PAGE_DESTINATION | MEMORY_SOURCE) == 0 && request.options & MEMORY_SOURCE == 0 && !request.source.is_null()), so requests thatexecute()will reject withE_NOTIMPLnever touchrequest.source.impl Drop for QueuedRead(lines 730–731).AI-assisted; synthetic tests only, no game files.
@Marvisak on GitHub · 2026-11-25 01:28 UTC · original · edited 2026-11-25 03:26 UTC
Automated triage for the maintainers.
Merge candidate. In
crates/victory-hle/src/modules/dstorage.rs,QueuedReadholds a reference on a request'sFilefromEnqueueRequestuntil the worker finishes the read, or untilClosediscards it, and the worker releases it beforefinishsignals the status array. A sharedSUPPORTED_OPTIONSmask now gates bothQueuedRead::newandexecute, so unsupported option bits such as bit 23 never touchsource;unsupported_options_do_not_touch_source_as_filecovers this. The null-outchecks inopen_file,create_status_arrayandcreate_queue, and the null check inread_into, are harmless. CI passes.On your reply: the blocking issue is fixed as described, and the description now calls the change defensive, which settles the evidence question.
Generated by Claude Code
@DenRakEiw on GitHub · 2026-11-25 02:57 UTC · original
Addressed all triage and review feedback (rebased onto
origin/main940d32f):SUPPORTED_OPTIONSguard): Extractedconst SUPPORTED_OPTIONS: u64 = ZLIB | BCPACK | PAGE_DESTINATION | MEMORY_SOURCEand shared it betweenQueuedRead::newandexecute.QueuedRead::newnow only callsadd_ref_instancewhenrequest.options & !SUPPORTED_OPTIONS == 0 && request.options & MEMORY_SOURCE == 0 && !request.source.is_null(), so unsupported option bits (e.g. bit 23 physical-page sources) never touchrequest.source.unsupported_options_do_not_touch_source_as_fileverifying that a bit-23 request leaves a sentinel source buffer untouched and fails withE_NOTIMPL.impl Drop for QueuedRead, updatedcount()forjob.read.request.optionsafter rebase, and clarified in the PR description that this is defensive COM lifetime handling per DirectStorage semantics.Re-verified locally:
cargo test -p victory-hle --lib dstorage::(18/18 passed),cargo clippy -p victory-hle --all-targets(0 warnings),cargo xtask policy(ok).AI-assisted (Gemini 4 Neon).
@Marvisak on GitHub · 2026-11-25 21:58 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because it no longer builds on
mainand fixes a case the title does not produce.Lanes::submit_asgained its physical-page hold logic (eddde734) after this branch was cut, and the merged build fails with three errors (r.optionson aCommand::Readthat now holds aQueuedRead, and two newer tests that readjob.request). The title never closes or releases its DirectStorage file objects and always passes out pointers to the factory, so the reference counting would rewire the scheduler's types for something it never does. It also collides with #1457 inLanes::start.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed