Validate XGameSave blob count before reading #1123

Open
github-bot wants to merge 2 commits from github-bot/gh-1123 into main AGit
Owner

@⁠EatCodeSleep2 on GitHub · 2026-11-24 15:57 UTC · original
EatCodeSleep2:fix/xgamesave-read-count → main · +32 −2 · 1 files · 2 commits · open

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.

**@⁠EatCodeSleep2** on GitHub · 2026-11-24 15:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/1123) `EatCodeSleep2:fix/xgamesave-read-count` → `main` · +32 −2 · 1 files · 2 commits · open ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:20:32 +00:00
Author
Owner

@⁠adamdotpy on GitHub · 2026-11-24 16:02 UTC · original

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.

**@⁠adamdotpy** on GitHub · 2026-11-24 16:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1123#issuecomment-7137017175) 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.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:01 UTC · original

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

**@⁠Zipettte** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1123#issuecomment-7140050967) 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)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:26 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1123#issuecomment-7149545717) <!-- 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1123/head:github-bot/gh-1123'
git switch 'github-bot/gh-1123'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1123'
git switch 'github-bot/gh-1123'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1123'
git switch 'github-bot/gh-1123'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1123'
git switch 'main'
git merge --squash 'github-bot/gh-1123'
git switch 'main'
git merge --ff-only 'github-bot/gh-1123'
git switch 'main'
git merge 'github-bot/gh-1123'
git push origin 'main'
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!1123
No description provided.