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

Closed
reeledMarek wants to merge 1 commit from upstream-pr/2525 into main
reeledMarek commented 2026-11-25 15:16:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:16:41Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6607728768 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2525). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:16:41Z. --- 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.
oni-swr commented 2026-11-25 16:09:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T15:37:35Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167132296 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2525#issuecomment-7167132296). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T15:37:35Z. --- **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).
Marvisak commented 2026-11-25 16:09:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:54:57Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167426167 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2525#issuecomment-7167426167). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:54:57Z. --- <!-- 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)_
jaschinski97-ops commented 2026-11-25 18:02:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jaschinski97-ops on 2026-11-25T18:00:25Z.

Review: COMMENTED


Native Windows 11 follow-up on unchanged head a805860: the new sharing-denied legacy-blob migration regression fails on main 13f91ca and passes with #2525. This fills the migration test gap identified in the earlier review.

A separate locked .display case still reproduces after #2525: unreadable metadata becomes empty and a partial version is committed. Scoped follow-up #2675 retains the original #2525 commit/author and adds the NotFound-only fallback plus Windows blob/display retry regressions and the absent-metadata control. It prevents fresh partial migrations; it does not claim to repair previously damaged versions.

Final HLE rerun150/150, Clippy alltargets/allfeatures with warnings denied and asset policy pass; the one earlier transient DirectStorage failure and successful reruns are documented in #2675. Rust1.98.1 WindowsGNU / LLVM-MinGW, native Windows11 build26300. AI-assisted with Codex; synthetic files only, no GPU/title data.

<!-- greyfinch-sync:Marvisak/VIctory:review:6062514933 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2525#pullrequestreview-6062514933). Originally posted by [jaschinski97-ops](https://github.com/jaschinski97-ops) on 2026-11-25T18:00:25Z. **Review:** COMMENTED --- Native Windows 11 follow-up on unchanged head `a805860`: the new sharing-denied legacy-blob migration regression fails on main `13f91ca` and passes with #2525. This fills the migration test gap identified in the earlier review. A separate locked `.display` case still reproduces after #2525: unreadable metadata becomes empty and a partial version is committed. Scoped follow-up #2675 retains the original #2525 commit/author and adds the NotFound-only fallback plus Windows blob/display retry regressions and the absent-metadata control. It prevents fresh partial migrations; it does not claim to repair previously damaged versions. Final HLE rerun150/150, Clippy alltargets/allfeatures with warnings denied and asset policy pass; the one earlier transient DirectStorage failure and successful reruns are documented in #2675. Rust1.98.1 WindowsGNU / LLVM-MinGW, native Windows11 build26300. AI-assisted with Codex; synthetic files only, no GPU/title data.
upstream-sync closed this pull request 2026-11-25 23:04:41 +00:00
Marvisak commented 2026-11-25 23:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:10:28Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176029495 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2525#issuecomment-7176029495). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:10:28Z. --- 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

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!2523
No description provided.