Skip to content

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

Closed
reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/hle-xgamesave-data-loss
Closed

reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/hle-xgamesave-data-loss

Conversation

@reeledMarek

Copy link
Copy Markdown
Contributor

Fixes #2497

Problem

  1. Version overflow data loss (XGameSave: a stray v18446744073709551615 folder makes an update lose the save in release builds (follow-up to #1729) #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

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Owner

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

@jaschinski97-ops jaschinski97-ops left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Marvisak

Copy link
Copy Markdown
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XGameSave: a stray v18446744073709551615 folder makes an update lose the save in release builds (follow-up to #1729)

4 participants