HLE: guard XGameSave version overflow and validate blobs before removing older versions #2525

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

@⁠reeledMarek on GitHub · 2026-11-25 15:16 UTC · original
reeledMarek:fix/hle-xgamesave-data-loss → main · +53 −13 · 1 files · 1 commits · closed without merging

Fixes #2497

Problem

  1. Version overflow data loss (#2497): Update::submit computed v.highest + 1. With a stray v18446744073709551615 (u64::MAX) folder next to a committed v1, debug builds panic and release builds wrap to v0 (ignored on read), return S_OK, and delete v1.
  2. Missing-blob data loss: load(dir) only verified manifest without checking that each listed blob file 0..blobs.len() exists as a regular file, so a newer version folder with a valid manifest and missing blob caused current() to delete intact older versions.
  3. Silent blob drop during migration: migrate() used filter_map with std::fs::read(e.path()).ok()?, silently omitting unreadable blobs before committing v1 and deleting the legacy folder.

Fix

  • Use v.highest.checked_add(1) in Update::submit, returning NO_ACCESS on overflow before writing or deleting anything.
  • Verify every manifest-listed blob file exists as a regular file in load(dir) (returning Ok(None) if missing/non-file, propagating other I/O errors).
  • Abort migrate() without deleting the legacy folder if any blob fails to read.

Testing

  • Extended an_unreadable_newer_version_does_not_cost_the_save with a missing blob case and added stray_u64_max_version_does_not_lose_the_save in crates/victory-hle/src/modules/xgamesave.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2525) `reeledMarek:fix/hle-xgamesave-data-loss` → `main` · +53 −13 · 1 files · 1 commits · closed without merging Fixes #2497 ### Problem 1. **Version overflow data loss (#2497):** `Update::submit` computed `v.highest + 1`. With a stray `v18446744073709551615` (`u64::MAX`) folder next to a committed `v1`, debug builds panic and release builds wrap to `v0` (ignored on read), return `S_OK`, and delete `v1`. 2. **Missing-blob data loss:** `load(dir)` only verified `manifest` without checking that each listed blob file `0..blobs.len()` exists as a regular file, so a newer version folder with a valid manifest and missing blob caused `current()` to delete intact older versions. 3. **Silent blob drop during migration:** `migrate()` used `filter_map` with `std::fs::read(e.path()).ok()?`, silently omitting unreadable blobs before committing `v1` and deleting the legacy folder. ### Fix - Use `v.highest.checked_add(1)` in `Update::submit`, returning `NO_ACCESS` on overflow before writing or deleting anything. - Verify every manifest-listed blob file exists as a regular file in `load(dir)` (returning `Ok(None)` if missing/non-file, propagating other I/O errors). - Abort `migrate()` without deleting the legacy folder if any blob fails to read. ### Testing - Extended `an_unreadable_newer_version_does_not_cost_the_save` with a `missing blob` case and added `stray_u64_max_version_does_not_lose_the_save` in `crates/victory-hle/src/modules/xgamesave.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:13 +00:00
github-bot closed this pull request 2026-11-26 05:08:13 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 15:37 UTC · original

Verification (Windows 11, WARP/CPU only) — head a805860e302d2dbc8db9218cca5ae9b577d82039, with overlap against #2511

Tested: the PR head = origin/main 940d32f + the PR (merge-base 940d32f, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1. VICTORY_D3D12_WARP=1 with --features diagnostics for victory-hle (WARP for any host device; xgamesave itself is filesystem-only). No physical GPU.

command result
cargo test -p victory-hle --locked --features diagnostics --lib xgamesave -- --test-threads=1 12 passed, 0 failed
... --lib stray_u64_max 1 passed
same test against origin/main's production code (tests kept) fails: panic at xgamesave.rs:511 (highest + 1 overflow)
... --lib an_unreadable_newer (new "missing blob" case) passes; fails against origin/main's production code (panic at xgamesave.rs:1038)
cargo test -p victory-hle --locked --features diagnostics --lib -- --test-threads=1 144 passed, 0 failed, 0 ignored
cargo clippy -p victory-hle --all-targets [--features diagnostics] --locked -- -D warnings clean
cargo xtask policy asset policy: 182 files ok

Diff read: the checked_add guard is the same as #2511's. load now stats each listed blob (0..n) and treats a missing or non-file blob as an unreadable version, so such a version is no longer picked as current and older versions are not removed behind it; migrate now aborts (None) on a failing read_dir entry or blob read instead of skipping it. Observations, not blockers: (1) the migrate change is a behaviour change with no test of its own (one permanently unreadable entry now blocks migrating that folder, where before the blob was dropped silently); (2) load now costs one metadata call per blob per version scanned; (3) only existence/is_file is checked, not size.

Side by side with #2511 (head b730d1e5): the overflow guard is the same single line (checked_add(1) -> NO_ACCESS); the two conflict textually at that hunk only. Resolving it with either side and both PRs' tests: 13 xgamesave tests pass; with this PR's side, full lib 145 passed, 0 failed and clippy clean. This PR is a superset of #2511 (adds blob validation in load, the stricter migrate, and one more test case); #2511 is just the overflow fix.

AI use: Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 15:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2525#issuecomment-7167132296) **Verification (Windows 11, WARP/CPU only) — head `a805860e302d2dbc8db9218cca5ae9b577d82039`, with overlap against #2511** Tested: the PR head = `origin/main` `940d32f` + the PR (merge-base `940d32f`, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1. `VICTORY_D3D12_WARP=1` with `--features diagnostics` for `victory-hle` (WARP for any host device; xgamesave itself is filesystem-only). No physical GPU. | command | result | |---|---| | `cargo test -p victory-hle --locked --features diagnostics --lib xgamesave -- --test-threads=1` | 12 passed, 0 failed | | `... --lib stray_u64_max` | 1 passed | | same test against `origin/main`'s production code (tests kept) | **fails**: panic at `xgamesave.rs:511` (`highest + 1` overflow) | | `... --lib an_unreadable_newer` (new "missing blob" case) | passes; fails against `origin/main`'s production code (panic at `xgamesave.rs:1038`) | | `cargo test -p victory-hle --locked --features diagnostics --lib -- --test-threads=1` | 144 passed, 0 failed, 0 ignored | | `cargo clippy -p victory-hle --all-targets [--features diagnostics] --locked -- -D warnings` | clean | | `cargo xtask policy` | `asset policy: 182 files ok` | Diff read: the `checked_add` guard is the same as #2511's. `load` now stats each listed blob (`0..n`) and treats a missing or non-file blob as an unreadable version, so such a version is no longer picked as current and older versions are not removed behind it; `migrate` now aborts (`None`) on a failing `read_dir` entry or blob read instead of skipping it. Observations, not blockers: (1) the `migrate` change is a behaviour change with no test of its own (one permanently unreadable entry now blocks migrating that folder, where before the blob was dropped silently); (2) `load` now costs one `metadata` call per blob per version scanned; (3) only existence/`is_file` is checked, not size. **Side by side with #2511 (head `b730d1e5`):** the overflow guard is the same single line (`checked_add(1)` -> `NO_ACCESS`); the two conflict textually at that hunk only. Resolving it with either side and both PRs' tests: 13 xgamesave tests pass; with this PR's side, full lib 145 passed, 0 failed and clippy clean. This PR is a superset of #2511 (adds blob validation in `load`, the stricter `migrate`, and one more test case); #2511 is just the overflow fix. AI use: Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:54 UTC · original

Automated triage for the maintainers. Merge candidate (a recommendation to look, not an approval).

In crates/victory-hle/src/modules/xgamesave.rs this fixes #2497 (Update::submit now refuses with NO_ACCESS when highest + 1 would overflow, instead of committing an unread v0 and removing v1), makes load treat a version whose listed blob files 0..n are missing as unreadable so current no longer removes older versions behind it (the second case named in #2497), and makes migrate keep the legacy folder when a blob fails to read instead of dropping that blob and deleting the folder. The overflow hunk is the same as #2511, which this PR includes, so only one of the two should land; the migrate change has no test of its own. CI: the check job passes.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2525#issuecomment-7167426167) <!-- victory-triage v1 head=a805860e302d2dbc8db9218cca5ae9b577d82039 verdict=merge-candidate at=2026-11-25T15:54:50Z --> Automated triage for the maintainers. Merge candidate (a recommendation to look, not an approval). In crates/victory-hle/src/modules/xgamesave.rs this fixes #2497 (`Update::submit` now refuses with `NO_ACCESS` when `highest + 1` would overflow, instead of committing an unread `v0` and removing `v1`), makes `load` treat a version whose listed blob files `0..n` are missing as unreadable so `current` no longer removes older versions behind it (the second case named in #2497), and makes `migrate` keep the legacy folder when a blob fails to read instead of dropping that blob and deleting the folder. The overflow hunk is the same as #2511, which this PR includes, so only one of the two should land; the `migrate` change has no test of its own. CI: the `check` job passes. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:10 UTC · original

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing as covered by two other PRs: the load hunk is #1981's with fewer tests, and the overflow hunk is #2511's line. The migrate change is untested and protects nothing: once the title saves under that name, the next provider open finds the new layout committed and deletes the legacy folder anyway.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 22:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2525#issuecomment-7176029495) Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing as covered by two other PRs: the `load` hunk is #1981's with fewer tests, and the overflow hunk is #2511's line. The `migrate` change is untested and protects nothing: once the title saves under that name, the next provider open finds the new layout committed and deletes the legacy folder anyway. If this is mistaken, reply here with what was missed 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!2525
No description provided.