xmem: check n * PAGE and base + len overflow in XMemMapPhysicalPages (#224) #247

Open
ending3729 wants to merge 1 commit from upstream-pr/247 into main
ending3729 commented 2026-11-26 12:38:44 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by ending3729 on 2026-11-26T12:38:44Z.


Fixes #224.

What changed

  • crates/victory-hle/src/modules/xmem.rs: in XMemMapPhysicalPages, check n.checked_mul(PAGE) and base.checked_add(len) before std::slice::from_raw_parts(pages, n) and unmap, returning null on overflow.
  • crates/victory-hle/src/modules/xmem.rs: in unmap, check base.checked_add(len) so end cannot wrap.
  • Added unit test modules::xmem::tests::map_physical_pages_rejects_overflowing_count_and_end (verified failing before the fix and passing after).

Tested

  • Windows 11 Build 26100, Ryzen 5 7500F, AMD Radeon RX 6600 XT 8 GB, Rust 1.98.1
  • cargo test -p victory-hle --locked: 156 passed, 0 failed, 2 ignored; no_dll_planting: 1 passed, 0 failed
  • cargo test -p xtask --locked: 9 passed, 0 failed
  • cargo clippy -p victory-hle --all-targets --locked --no-deps -- -D warnings: 0 warnings
  • Not tested: live GTA VI title run (no local game dump)

AI use

  • Antigravity (Gemini 4 Neon) assisted with code inspection, patch authoring, and local test verification.
<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6626819698 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/247). Originally posted by [ending3729](https://github.com/ending3729) on 2026-11-26T12:38:44Z. --- Fixes #224. **What changed** - `crates/victory-hle/src/modules/xmem.rs`: in `XMemMapPhysicalPages`, check `n.checked_mul(PAGE)` and `base.checked_add(len)` before `std::slice::from_raw_parts(pages, n)` and `unmap`, returning null on overflow. - `crates/victory-hle/src/modules/xmem.rs`: in `unmap`, check `base.checked_add(len)` so `end` cannot wrap. - Added unit test `modules::xmem::tests::map_physical_pages_rejects_overflowing_count_and_end` (verified failing before the fix and passing after). **Tested** - Windows 11 Build 26100, Ryzen 5 7500F, AMD Radeon RX 6600 XT 8 GB, Rust 1.98.1 - `cargo test -p victory-hle --locked`: 156 passed, 0 failed, 2 ignored; `no_dll_planting`: 1 passed, 0 failed - `cargo test -p xtask --locked`: 9 passed, 0 failed - `cargo clippy -p victory-hle --all-targets --locked --no-deps -- -D warnings`: 0 warnings - Not tested: live GTA VI title run (no local game dump) **AI use** - Antigravity (Gemini 4 Neon) assisted with code inspection, patch authoring, and local test verification.
lerapeurdu62280-debug commented 2026-11-26 14:16:04 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by lerapeurdu62280-debug on 2026-11-26T14:16:04Z.


Read the diff. checked_mul/checked_add before from_raw_parts and in unmap close a real wrap on title-supplied n/address, and the test covers both the count and the end overflow.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:review:6075636017 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/247#pullrequestreview-6075636017). Originally posted by [lerapeurdu62280-debug](https://github.com/lerapeurdu62280-debug) on 2026-11-26T14:16:04Z. --- Read the diff. checked_mul/checked_add before from_raw_parts and in unmap close a real wrap on title-supplied n/address, and the test covers both the count and the end overflow.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/247:upstream-pr/247'
git switch 'upstream-pr/247'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/247'
git switch 'upstream-pr/247'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/247'
git switch 'upstream-pr/247'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/247'
git switch 'main'
git merge --squash 'upstream-pr/247'
git switch 'main'
git merge --ff-only 'upstream-pr/247'
git switch 'main'
git merge 'upstream-pr/247'
git push origin 'main'
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
avatarmanz/VIctory-7900XTX!247
No description provided.