HLE: check null and invalid handle in display deferral #531
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/531"
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 pushkarreddyy on 2026-11-24T04:32:34Z.
Motivation
In
crates/victory-hle/src/modules/display.rs:acquire_deferralonly checkedrequest as isize == -1afterPowerCreateRequest(&context). In the Windows API, handle failure may return null (0) orINVALID_HANDLE_VALUE(-1). Checking both guarantees a null handle is not treated as a successful power request.close_deferralchecked!handle.is_null()but did not guard against pseudo-handle or invalid handle-1, which would invokeCloseHandle(-1).Solution
PowerCreateRequestresult withrequest.is_null() || request as isize == -1.close_deferralwith!handle.is_null() && handle as isize != -1.acquire_deferraland graceful null/invalid handling inclose_deferral.No game files used.
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T04:51:26Z.
### Technical Verification & Implementation Details
Context & Root Cause
In
crates/victory-hle/src/modules/display.rs:acquire_deferralonly checkedrequest as isize == -1after callingPowerCreateRequest(&context). In the Windows API, handle failure may return null (0) orINVALID_HANDLE_VALUE(-1). Checking both ensures null handles are not treated as valid power requests.close_deferralchecked!handle.is_null()but did not guard against pseudo/invalid handle-1, which would attempt an invalidCloseHandle(-1)call.Changes & Diff
PowerCreateRequestresult withrequest.is_null() || request as isize == -1.close_deferralwith!handle.is_null() && handle as isize != -1.acquire_deferral_rejects_null_outandclose_deferral_handles_null_and_invalid.Git Log Line & Verification
ext 7f0053b HLE: check null and invalid handle in display deferral crates/victory-hle/src/modules/display.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)cargo xtask policy(Rule #1 compliance, zero game assets).rustfmt --edition 2024.Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T06:24:07Z.
### Call for Testing & Maintainer Review
Community members testing game initialization or HLE modules on Windows 10/11: verification and feedback on this PR is warmly welcome!
cargo xtask policypassing).@Marvisak: Ready for maintainer review and merge when convenient!
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T07:37:38Z.
Review: APPROVED
Tested
7f0053bon Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (266 passed, 0 failed).PowerCreateRequestdocumentsINVALID_HANDLE_VALUEon failure. Also rejecting null is harmless defensiveness, since a null request would only fail later inPowerSetRequest.CloseHandle(-1)is right:-1is the current-process pseudo-handle, and closing it is a no-op error at best.No issues found.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T08:20:39Z.
Thank you @mercuryVM for testing and verifying on Windows 11 / MSVC! Appreciate the confirmation and approval on the handle validation.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:03:53Z.
Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).
No observable effect: a null request from PowerCreateRequest already fails at PowerSetRequest and returns an error, and -1 is never handed out as a deferral handle. The new tests cover behaviour main already has.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed