HLE: check null and invalid handle in display deferral #531

Closed
github-bot wants to merge 1 commit from gh-pr/531/head into gh-pr/531/base
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 04:32 UTC · original
pushkarreddyy:fix/display-deferral-handle-check → main · +18 −2 · 1 files · 1 commits · closed without merging

Motivation

In crates/victory-hle/src/modules/display.rs:

  • acquire_deferral only checked request as isize == -1 after PowerCreateRequest(&context). In the Windows API, handle failure may return null (0) or INVALID_HANDLE_VALUE (-1). Checking both guarantees a null handle is not treated as a successful power request.
  • close_deferral checked !handle.is_null() but did not guard against pseudo-handle or invalid handle -1, which would invoke CloseHandle(-1).

Solution

  • Guard PowerCreateRequest result with request.is_null() || request as isize == -1.
  • Guard close_deferral with !handle.is_null() && handle as isize != -1.
  • Added unit tests for null output rejection in acquire_deferral and graceful null/invalid handling in close_deferral.

No game files used.

**@⁠pushkarreddyy** on GitHub · 2026-11-24 04:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/531) `pushkarreddyy:fix/display-deferral-handle-check` → `main` · +18 −2 · 1 files · 1 commits · closed without merging ## Motivation In `crates/victory-hle/src/modules/display.rs`: - `acquire_deferral` only checked `request as isize == -1` after `PowerCreateRequest(&context)`. In the Windows API, handle failure may return null (`0`) or `INVALID_HANDLE_VALUE` (`-1`). Checking both guarantees a null handle is not treated as a successful power request. - `close_deferral` checked `!handle.is_null()` but did not guard against pseudo-handle or invalid handle `-1`, which would invoke `CloseHandle(-1)`. ## Solution - Guard `PowerCreateRequest` result with `request.is_null() || request as isize == -1`. - Guard `close_deferral` with `!handle.is_null() && handle as isize != -1`. - Added unit tests for null output rejection in `acquire_deferral` and graceful null/invalid handling in `close_deferral`. No game files used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:07:19 +00:00
github-bot closed this pull request 2026-11-26 04:07:19 +00:00
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 04:51 UTC · original

### Technical Verification & Implementation Details

Context & Root Cause

In crates/victory-hle/src/modules/display.rs:

  • acquire_deferral only checked request as isize == -1 after calling PowerCreateRequest(&context). In the Windows API, handle failure may return null (0) or INVALID_HANDLE_VALUE (-1). Checking both ensures null handles are not treated as valid power requests.
  • close_deferral checked !handle.is_null() but did not guard against pseudo/invalid handle -1, which would attempt an invalid CloseHandle(-1) call.

Changes & Diff

  • Guarded PowerCreateRequest result with request.is_null() || request as isize == -1.
  • Guarded close_deferral with !handle.is_null() && handle as isize != -1.
  • Added unit tests acquire_deferral_rejects_null_out and close_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(-)

  • Passes cargo xtask policy (Rule #1 compliance, zero game assets).
  • Formatted with rustfmt --edition 2024.
**@⁠pushkarreddyy** on GitHub · 2026-11-24 04:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/531#issuecomment-7122400529) ### Technical Verification & Implementation Details #### Context & Root Cause In `crates/victory-hle/src/modules/display.rs`: - `acquire_deferral` only checked `request as isize == -1` after calling `PowerCreateRequest(&context)`. In the Windows API, handle failure may return null (`0`) or `INVALID_HANDLE_VALUE` (`-1`). Checking both ensures null handles are not treated as valid power requests. - `close_deferral` checked `!handle.is_null()` but did not guard against pseudo/invalid handle `-1`, which would attempt an invalid `CloseHandle(-1)` call. #### Changes & Diff - Guarded `PowerCreateRequest` result with `request.is_null() || request as isize == -1`. - Guarded `close_deferral` with `!handle.is_null() && handle as isize != -1`. - Added unit tests `acquire_deferral_rejects_null_out` and `close_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(-) ` - Passes `cargo xtask policy` (Rule #1 compliance, zero game assets). - Formatted with `rustfmt --edition 2024`.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 06:24 UTC · original

### 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!

  • Rule #1 asset policy compliant (cargo xtask policy passing).
  • Formatted with Rust 2024.

@⁠Marvisak: Ready for maintainer review and merge when convenient!

**@⁠pushkarreddyy** on GitHub · 2026-11-24 06:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/531#issuecomment-7123894534) ### 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! - Rule #1 asset policy compliant (`cargo xtask policy` passing). - Formatted with Rust 2024. @⁠Marvisak: Ready for maintainer review and merge when convenient!
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 08:20 UTC · original

Thank you @⁠mercuryVM for testing and verifying on Windows 11 / MSVC! Appreciate the confirmation and approval on the handle validation.

**@⁠pushkarreddyy** on GitHub · 2026-11-24 08:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/531#issuecomment-7126019287) Thank you @⁠mercuryVM for testing and verifying on Windows 11 / MSVC! Appreciate the confirmation and approval on the handle validation.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:03 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/531#issuecomment-7148097726) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!531
No description provided.