HLE: validate null pointer in ApuIsVirtualAddressValid and overflow in ApuAlloc #528

Closed
pushkarreddyy wants to merge 1 commit from upstream-pr/528 into main
pushkarreddyy commented 2026-11-24 04:28:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T04:28:19Z.


Problem

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

  • ApuIsVirtualAddressValid does not short-circuit on null pointers before calling heap_map(0).
  • ApuMapVirtualAddress does not check for null input.
  • ApuAlloc does not check for arithmetic overflow when validating size and align.

Fix

  • Immediately return false if ptr.is_null() in ApuIsVirtualAddressValid.
  • Immediately return 0 if ptr.is_null() in ApuMapVirtualAddress.
  • Reject integer overflow via size.checked_add(align).is_none() in ApuAlloc.
  • Added unit test coverage for null pointer guards and overflow validation.

No game files used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574622427 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T04:28:19Z. --- ## Problem In `crates/victory-hle/src/modules/audio.rs`: - `ApuIsVirtualAddressValid` does not short-circuit on null pointers before calling `heap_map(0)`. - `ApuMapVirtualAddress` does not check for null input. - `ApuAlloc` does not check for arithmetic overflow when validating `size` and `align`. ## Fix - Immediately return `false` if `ptr.is_null()` in `ApuIsVirtualAddressValid`. - Immediately return `0` if `ptr.is_null()` in `ApuMapVirtualAddress`. - Reject integer overflow via `size.checked_add(align).is_none()` in `ApuAlloc`. - Added unit test coverage for null pointer guards and overflow validation. No game files used.
LAKSHYA-cmd-tech commented 2026-11-24 06:53:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T04:51:30Z.

Review: APPROVED


Verified on Windows 11:

  • All 87 unit and integration tests in \ ictory-hle\ pass.
  • Null pointer validation in \ApuIsVirtualAddressValid\ and \ApuMapVirtualAddress\ avoids redundant lookups on null.
  • \size.checked_add(align).is_none()\ in \ApuAlloc\ properly prevents integer overflow.
  • \cargo xtask policy\ passes (151 files checked, zero violations).
<!-- greyfinch-sync:Marvisak/VIctory:review:6033819606 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528#pullrequestreview-6033819606). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T04:51:30Z. **Review:** APPROVED --- Verified on Windows 11: - All 87 unit and integration tests in \ ictory-hle\ pass. - Null pointer validation in \ApuIsVirtualAddressValid\ and \ApuMapVirtualAddress\ avoids redundant lookups on null. - \size.checked_add(align).is_none()\ in \ApuAlloc\ properly prevents integer overflow. - \cargo xtask policy\ passes (151 files checked, zero violations).
pushkarreddyy commented 2026-11-24 06:55:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T04:51:23Z.


### Technical Verification & Implementation Details

Context & Root Cause

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

  1. ApuIsVirtualAddressValid called heap_map(0) when passed null pointers instead of short-circuiting to false.
  2. ApuMapVirtualAddress did not check for null pointer input.
  3. ApuAlloc performed unbounded arithmetic size + align without overflow checks.

Changes & Diff

  • Return 0 (false) immediately if ptr.is_null() in ApuIsVirtualAddressValid.
  • Return 0 immediately if ptr.is_null() in ApuMapVirtualAddress.
  • Enforced overflow check size.checked_add(align).is_none() in ApuAlloc.
  • Added unit test suite covering null handling and overflow protection.

Git Log Line & Verification

ext b1539b7 HLE: validate null pointer in ApuIsVirtualAddressValid and overflow in ApuAlloc crates/victory-hle/src/modules/audio.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)

  • Passes cargo xtask policy (Rule #1 compliance, zero game assets).
  • Formatted with rustfmt --edition 2024.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7122399751 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528#issuecomment-7122399751). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T04:51:23Z. --- ### Technical Verification & Implementation Details #### Context & Root Cause In `crates/victory-hle/src/modules/audio.rs`: 1. `ApuIsVirtualAddressValid` called `heap_map(0)` when passed null pointers instead of short-circuiting to `false`. 2. `ApuMapVirtualAddress` did not check for null pointer input. 3. `ApuAlloc` performed unbounded arithmetic `size + align` without overflow checks. #### Changes & Diff - Return `0` (false) immediately if `ptr.is_null()` in `ApuIsVirtualAddressValid`. - Return `0` immediately if `ptr.is_null()` in `ApuMapVirtualAddress`. - Enforced overflow check `size.checked_add(align).is_none()` in `ApuAlloc`. - Added unit test suite covering null handling and overflow protection. #### Git Log Line & Verification ` ext b1539b7 HLE: validate null pointer in ApuIsVirtualAddressValid and overflow in ApuAlloc crates/victory-hle/src/modules/audio.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) ` - Passes `cargo xtask policy` (Rule #1 compliance, zero game assets). - Formatted with `rustfmt --edition 2024`.
pushkarreddyy commented 2026-11-24 06:56:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T06:15:01Z.


Thank you @LAKSHYA-cmd-tech for testing and verifying on Windows 11! Glad all 87 tests and asset policy passed cleanly.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123739312 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528#issuecomment-7123739312). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T06:15:01Z. --- Thank you @LAKSHYA-cmd-tech for testing and verifying on Windows 11! Glad all 87 tests and asset policy passed cleanly.
pushkarreddyy commented 2026-11-24 06:56:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T06:23:41Z.


### Ready for Merge
Verified and approved on Windows 11 by @LAKSHYA-cmd-tech (all unit tests passing, zero Clippy warnings, asset policy passing).

@Marvisak: Ready for maintainer review and merge when you have time!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123887269 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528#issuecomment-7123887269). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T06:23:41Z. --- ### Ready for Merge Verified and approved on Windows 11 by @LAKSHYA-cmd-tech (all unit tests passing, zero Clippy warnings, asset policy passing). @Marvisak: Ready for maintainer review and merge when you have time!
mercuryVM commented 2026-11-24 12:03:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:56:38Z.

Review: APPROVED


Tested b1539b7 on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 87 passed, including the new null and overflow assertions. Clippy's 1 warning is the existing field_reassign_with_default at xmem.rs:747.

  • The null checks in ApuIsVirtualAddressValid and ApuMapVirtualAddress run before any heap lookup, and size.checked_add(align) rejects an ApuAlloc whose aligned size would wrap.
  • The remaining hunks in audio.rs are formatting only. Fine, though a separate commit would keep the functional diff easier to read.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038744692 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528#pullrequestreview-6038744692). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:56:38Z. **Review:** APPROVED --- Tested b1539b7 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-hle` 87 passed, including the new null and overflow assertions. Clippy's 1 warning is the existing `field_reassign_with_default` at xmem.rs:747. - The null checks in `ApuIsVirtualAddressValid` and `ApuMapVirtualAddress` run before any heap lookup, and `size.checked_add(align)` rejects an `ApuAlloc` whose aligned size would wrap. - The remaining hunks in `audio.rs` are formatting only. Fine, though a separate commit would keep the functional diff easier to read. AI-assisted (Claude Code).
pushkarreddyy commented 2026-11-24 13:02:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T12:38:21Z.


Thank you @mercuryVM for testing and approving!

Acknowledged on keeping functional diffs strictly separated from formatting hunks—I'll ensure future HLE PRs isolate formatting into dedicated commits for maximum review clarity.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7131717250 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528#issuecomment-7131717250). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T12:38:21Z. --- Thank you @mercuryVM for testing and approving! Acknowledged on keeping functional diffs strictly separated from formatting hunks—I'll ensure future HLE PRs isolate formatting into dedicated commits for maximum review clarity.
pushkarreddyy commented 2026-11-24 13:02:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T13:01:50Z.


@Marvisak: PR #528 has approvals from both @LAKSHYA-cmd-tech and @mercuryVM (verified clean on Windows 11 MSVC with all 87 HLE tests passing and Rule #1 compliant). Whenever you have a moment, this is ready to merge!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7132250124 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528#issuecomment-7132250124). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T13:01:50Z. --- @Marvisak: PR #528 has approvals from both @LAKSHYA-cmd-tech and @mercuryVM (verified clean on Windows 11 MSVC with all 87 HLE tests passing and Rule #1 compliant). Whenever you have a moment, this is ready to merge!
upstream-sync closed this pull request 2026-11-25 00:05:35 +00:00
Marvisak commented 2026-11-25 00:06:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:03:49Z.


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).

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148096518 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/528#issuecomment-7148096518). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:03:49Z. --- 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). 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

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!528
No description provided.