Validate XGameSave blob count before reading #1123

Open
EatCodeSleep2 wants to merge 2 commits from upstream-pr/1123 into main
EatCodeSleep2 commented 2026-11-24 15:57:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by EatCodeSleep2 on 2026-11-24T15:57:22Z.


Summary

  • Return E_INVALIDARG when the required blob-count pointer is null in the synchronous and asynchronous XGameSave read entry points.
  • Validate the asynchronous result pointer before consuming the outstanding result so the caller can retry.
  • Extend the synthetic save regression to check both invalid calls, untouched output, and a successful retry.

Testing

cargo test --locked -p victory-hle --lib modules::xgamesave::tests::saves_persist_across_providers -- --exact

AI-assisted. Uses synthetic save data only.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6585914224 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1123). Originally posted by [EatCodeSleep2](https://github.com/EatCodeSleep2) on 2026-11-24T15:57:22Z. --- ## Summary - Return `E_INVALIDARG` when the required blob-count pointer is null in the synchronous and asynchronous XGameSave read entry points. - Validate the asynchronous result pointer before consuming the outstanding result so the caller can retry. - Extend the synthetic save regression to check both invalid calls, untouched output, and a successful retry. ## Testing `cargo test --locked -p victory-hle --lib modules::xgamesave::tests::saves_persist_across_providers -- --exact` AI-assisted. Uses synthetic save data only.
DenRakEiw commented 2026-11-24 16:04:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T16:01:25Z.

Review: APPROVED


Tested merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-hle: 94 passed, 0 failed (plus no_dll_planting: 1 passed)
  • cargo clippy -p victory-hle --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean validation of XGameSave blob counts before reading. Approving.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6042812772 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1123#pullrequestreview-6042812772). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T16:01:25Z. **Review:** APPROVED --- Tested merged cleanly onto `main` (`ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC): - `cargo test -p victory-hle`: **94 passed, 0 failed** (plus `no_dll_planting`: 1 passed) - `cargo clippy -p victory-hle --all-targets`: **0 warnings** - `cargo xtask policy`: ok Clean validation of `XGameSave` blob counts before reading. Approving. AI-assisted (Gemini 4 Neon).
adamdotpy commented 2026-11-24 16:05:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T16:02:14Z.


Reviewed on Windows 11 / Rust 1.98.1. The checks are in the right place and for a better reason than "put would have caught it":

  • put already returns E_INVALIDARG for a null out-pointer, but only after the write. In read_blobs that is after out.copy_from_nonoverlapping, and in read_result after the whole pointer-fixup loop in the title's buffer. So without this, a title passing a null count got its buffer written and then E_INVALIDARG — half-done work it could not see. Returning before any of it is the fix, and assert!(buffer.iter().all(|&word| word == 0)) in both new tests is exactly the property that pins it.
  • read_result also returns before XAsyncGetResult, so the result stays for a retry, the same contract the BUFFER_TOO_SMALL branch has. Good; that ordering is the part a later edit could quietly break, so it is worth the sentence in the comment that you already have.

Build state on the branch as pushed. Clippy fails, but not on your code:

error: unnecessary parentheses
  --> crates\victory-hle\src\modules\xasync.rs:1182:22

The branch is one merge behind — its base is 58fed37 and xasync.rs there still has call((&raw mut block)), which current main has as call(&raw mut block). After git merge upstream/main (which brings only main's changes), cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings is clean and cargo test -p victory-hle gives 94 passed in the lib and 1 in the next target, so your file needs nothing. Merging main in clears the red check on the PR.

One gap worth closing while you are in this function. count is now a required input, but names(blob_names, wanted) returns None for a null names array, and read treats None as "every blob in the container" (names.unwrap_or_else(|| version.blobs.clone())). So a title that passes blob_names = null with count = 2 gets all of its blobs, count written back as the real total, and BUFFER_TOO_SMALL if it sized the buffer for two. Nothing in the branch changes that — it predates this PR — but it is the same class of bug: an argument that says what the title wants, ignored. Either E_INVALIDARG for null names with count > 0, or a // shortcut: a null array means the whole container comment, and a test says which. There is no test for null names with a non-null count today.

Style, non-blocking. This module returns E_INVALIDARG here and elsewhere for bad handles; dsp.rs and media.rs use E_POINTER for "a required out-pointer is null" specifically. Either is defensible, but if the crate wants one rule, this is the pair of functions where it shows.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137017175 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1123#issuecomment-7137017175). Originally posted by [adamdotpy](https://github.com/adamdotpy) on 2026-11-24T16:02:14Z. --- Reviewed on Windows 11 / Rust 1.98.1. The checks are in the right place and for a better reason than "`put` would have caught it": - `put` already returns `E_INVALIDARG` for a null out-pointer, but only *after* the write. In `read_blobs` that is after `out.copy_from_nonoverlapping`, and in `read_result` after the whole pointer-fixup loop in the title's buffer. So without this, a title passing a null count got its buffer written and then `E_INVALIDARG` — half-done work it could not see. Returning before any of it is the fix, and `assert!(buffer.iter().all(|&word| word == 0))` in both new tests is exactly the property that pins it. - `read_result` also returns before `XAsyncGetResult`, so the result stays for a retry, the same contract the `BUFFER_TOO_SMALL` branch has. Good; that ordering is the part a later edit could quietly break, so it is worth the sentence in the comment that you already have. **Build state on the branch as pushed.** Clippy fails, but not on your code: ``` error: unnecessary parentheses --> crates\victory-hle\src\modules\xasync.rs:1182:22 ``` The branch is one merge behind — its base is `58fed37` and `xasync.rs` there still has `call((&raw mut block))`, which current `main` has as `call(&raw mut block)`. After `git merge upstream/main` (which brings only main's changes), `cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings` is clean and `cargo test -p victory-hle` gives 94 passed in the lib and 1 in the next target, so your file needs nothing. Merging `main` in clears the red check on the PR. **One gap worth closing while you are in this function.** `count` is now a required input, but `names(blob_names, wanted)` returns `None` for a null *names* array, and `read` treats `None` as "every blob in the container" (`names.unwrap_or_else(|| version.blobs.clone())`). So a title that passes `blob_names = null` with `count = 2` gets all of its blobs, `count` written back as the real total, and `BUFFER_TOO_SMALL` if it sized the buffer for two. Nothing in the branch changes that — it predates this PR — but it is the same class of bug: an argument that says what the title wants, ignored. Either `E_INVALIDARG` for null names with `count > 0`, or a `// shortcut: a null array means the whole container` comment, and a test says which. There is no test for null names with a non-null count today. **Style, non-blocking.** This module returns `E_INVALIDARG` here and elsewhere for bad handles; `dsp.rs` and `media.rs` use `E_POINTER` for "a required out-pointer is null" specifically. Either is defensible, but if the crate wants one rule, this is the pair of functions where it shows.
Zipettte commented 2026-11-24 18:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:01:40Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 4e32dfc: cargo test -p victory-hle passes, 95 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140050967 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1123#issuecomment-7140050967). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T18:01:40Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 4e32dfc: `cargo test -p victory-hle` passes, 95 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
mercuryVM commented 2026-11-24 19:02:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T18:50:34Z.

Review: APPROVED


Tested 4e32dfc on Windows 11, RTX 5070, MSVC: builds, cargo test --workspace --no-fail-fast 602 passed, 0 failed (on our fork main). saves_persist_across_providers passes with the new invalid calls.

  • countOfBlobs is a required in/out pointer for both XGameSaveReadBlobData and XGameSaveReadBlobDataResult, so E_INVALIDARG for null matches the GDK.
  • In read_result the check comes before XAsyncGetResult, so the result isn't consumed and a retry with a valid pointer succeeds, which the test checks along with the untouched buffer.
  • In read_blobs, refusing null instead of treating it as 0 changes behaviour only for an invalid call. That's fine.

Merged into our fork's main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6045348847 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1123#pullrequestreview-6045348847). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T18:50:34Z. **Review:** APPROVED --- Tested 4e32dfc on Windows 11, RTX 5070, MSVC: builds, `cargo test --workspace --no-fail-fast` 602 passed, 0 failed (on our fork main). `saves_persist_across_providers` passes with the new invalid calls. - `countOfBlobs` is a required in/out pointer for both `XGameSaveReadBlobData` and `XGameSaveReadBlobDataResult`, so `E_INVALIDARG` for null matches the GDK. - In `read_result` the check comes before `XAsyncGetResult`, so the result isn't consumed and a retry with a valid pointer succeeds, which the test checks along with the untouched buffer. - In `read_blobs`, refusing null instead of treating it as 0 changes behaviour only for an invalid call. That's fine. Merged into our fork's main. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 02:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:26:18Z.


Automated triage for the maintainers.

Proposed close.

This makes read_blobs and read_result in crates/victory-hle/src/modules/xgamesave.rs return E_INVALIDARG up front when the blob-count pointer is null. On main that call already ends in E_INVALIDARG, through put(count, ..). The only difference is that the title's buffer is not written first, on a failure path.

The count is a required in/out argument of these reads. A title that passes null there would not get its saves on the console either, and nothing in the PR shows the title, or any title, doing so. That makes this a guard for a case that does not occur, and it changes runtime return order with no reference for what the console runtime does. The PR gives no evidence for that behaviour.

What would change this: evidence (from the title's own code or public documentation) that a null count reaches these entry points and what the runtime returns for it. The null-blob_names gap raised in the thread would be a separate change, with the same kind of evidence.

CI: check passes.

This pull request will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149545717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1123#issuecomment-7149545717). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:26:18Z. --- <!-- victory-triage v1 head=4e32dfc7866ec6e904c648e2bbab2aa42d26ccb0 verdict=proposed-close at=2026-11-25T01:26:16Z --> Automated triage for the maintainers. **Proposed close.** This makes `read_blobs` and `read_result` in `crates/victory-hle/src/modules/xgamesave.rs` return `E_INVALIDARG` up front when the blob-count pointer is null. On `main` that call already ends in `E_INVALIDARG`, through `put(count, ..)`. The only difference is that the title's buffer is not written first, on a failure path. The count is a required in/out argument of these reads. A title that passes null there would not get its saves on the console either, and nothing in the PR shows the title, or any title, doing so. That makes this a guard for a case that does not occur, and it changes runtime return order with no reference for what the console runtime does. The PR gives no evidence for that behaviour. What would change this: evidence (from the title's own code or public documentation) that a null count reaches these entry points and what the runtime returns for it. The null-`blob_names` gap raised in the thread would be a separate change, with the same kind of evidence. CI: `check` passes. This pull request will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
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/1123:upstream-pr/1123'
git switch 'upstream-pr/1123'

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/1123'
git switch 'upstream-pr/1123'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1123'
git switch 'upstream-pr/1123'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1123'
git switch 'main'
git merge --squash 'upstream-pr/1123'
git switch 'main'
git merge --ff-only 'upstream-pr/1123'
git switch 'main'
git merge 'upstream-pr/1123'
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
Marvisak/VIctory!1123
No description provided.