XGameSave: an unreadable legacy blob keeps the old layout #383

Closed
github-bot wants to merge 2 commits from gh-pr/383/head into gh-pr/383/base
Owner

@⁠JordanFableFur on GitHub · 2026-11-25 00:12 UTC · original
JordanFableFur:fix/gamesave-migrate-keeps-old-on-error → main · +82 −9 · 1 files · 2 commits · closed without merging

What

The legacy-to-versioned migration's iterator chain skipped a blob it could not read and committed the rest: a legacy directory with one unreadable file moved over with that blob silently dropped, and the old directory was removed, so the save lost data for good.

The migration now fails whole when a recognized blob cannot be read: the old directory keeps its files so a later call can retry, and unrelated names stay skipped (the optional .display metadata behaves as before).

Fixes #242.

Testing

A regression (unix-gated: it uses file permissions) makes one of two blobs unreadable, opens the provider, and checks the old layout is untouched; with the permission restored, a retry migrates both blobs and removes the old directory. The existing migration test is unchanged and passes.

Validated on Windows CI (fork-run of the repository workflow): clippy both builds and the full test suite pass: https://github.com/JordanFableFur/victory-fork/actions/runs/45515840303

AI use: written with Codex and Claude Code (GPT-5.2 Codex); reviewed and posted with my approval. No game files were used.

**@⁠JordanFableFur** on GitHub · 2026-11-25 00:12 UTC · [original](https://github.com/fxceless/victory-fork/pull/383) `JordanFableFur:fix/gamesave-migrate-keeps-old-on-error` → `main` · +82 −9 · 1 files · 2 commits · closed without merging ## What The legacy-to-versioned migration's iterator chain skipped a blob it could not read and committed the rest: a legacy directory with one unreadable file moved over with that blob silently dropped, and the old directory was removed, so the save lost data for good. The migration now fails whole when a recognized blob cannot be read: the old directory keeps its files so a later call can retry, and unrelated names stay skipped (the optional `.display` metadata behaves as before). Fixes #242. ## Testing A regression (unix-gated: it uses file permissions) makes one of two blobs unreadable, opens the provider, and checks the old layout is untouched; with the permission restored, a retry migrates both blobs and removes the old directory. The existing migration test is unchanged and passes. Validated on Windows CI (fork-run of the repository workflow): clippy both builds and the full test suite pass: https://github.com/JordanFableFur/victory-fork/actions/runs/45515840303 **AI use:** written with Codex and Claude Code (GPT-5.2 Codex); reviewed and posted with my approval. No game files were used.
The migration's iterator chain skipped a blob it could not read and
committed the rest: a legacy directory with an unreadable file moved
over with that blob dropped, and the old directory was removed, so the
save lost data for good.

The migration now fails whole when a recognized blob cannot be read:
the old directory keeps its files for a later call to retry, and
unrelated names stay skipped. A regression makes a blob unreadable
(0o600 restored after), checks the old layout is untouched, then that a
retry with the permission back moves both blobs.

AI use: written with Codex and Claude Code (GPT-5.2 Codex); reviewed and
posted with my approval. No game files were used.
Review of the first fix: with the migration blocked on an unreadable
blob, an update to the container still committed a version holding only
the submitted blobs, and the next scan then cleared the old directory
as done — even the readable legacy blobs were gone.

An update refuses while a legacy directory of the container's name sits
under the root (the migration has not gone through); once it has, the
update commits as before. The regression now checks the refusal, and
its unreadable blob skips itself where privileges would ignore the
mode.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:10 +00:00
github-bot closed this pull request 2026-11-26 03:42:10 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:13 UTC · original · edited 2026-11-25 00:16 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T00:16:40.620236Z 3ae02f7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:13 UTC · [original](https://github.com/fxceless/victory-fork/pull/383#issuecomment-7148274376) · edited 2026-11-25 00:16 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"3ae02f70b1851492475c40daa162106f67dc079e","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T00:16:40.620236Z">2026-11-25T00:16:40.620236Z</relative-time> | `3ae02f7` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠kaayzouee on GitHub · 2026-11-25 00:24 UTC · original

Duplicate of #322?

**@⁠kaayzouee** on GitHub · 2026-11-25 00:24 UTC · [original](https://github.com/fxceless/victory-fork/pull/383#issuecomment-7148485050) Duplicate of #322?
Author
Owner

@⁠JordanFableFur on GitHub · 2026-11-25 00:33 UTC · original

Both findings addressed in ff1da6c:

  • Update::submit refuses while a legacy directory of the container's name sits under the root (the migration has not gone through), so an update can no longer commit a version that leaves the legacy blobs out; the regression checks the refusal, and the retry path still migrates both blobs.
  • The permission fixture returns early when the read still succeeds (privileged processes ignore the mode), so it skips itself where the premise does not hold.
**@⁠JordanFableFur** on GitHub · 2026-11-25 00:33 UTC · [original](https://github.com/fxceless/victory-fork/pull/383#issuecomment-7148623878) Both findings addressed in ff1da6c: - `Update::submit` refuses while a legacy directory of the container's name sits under the root (the migration has not gone through), so an update can no longer commit a version that leaves the legacy blobs out; the regression checks the refusal, and the retry path still migrates both blobs. - The permission fixture returns early when the read still succeeds (privileged processes ignore the mode), so it skips itself where the premise does not hold.
Author
Owner

@⁠JordanFableFur on GitHub · 2026-11-25 01:46 UTC · original

Closing — #322 fixes the same issue (#242) and was opened first. One thing I did not see covered there and worth carrying into review: while a legacy directory is stuck (its migration failing whole on an unreadable blob), an update to the container can still commit a fresh version holding only the submitted blobs, and the next scan then clears the old directory as done — the readable legacy blobs are lost. Refusing updates to that container until the migration goes through closes it.

**@⁠JordanFableFur** on GitHub · 2026-11-25 01:46 UTC · [original](https://github.com/fxceless/victory-fork/pull/383#issuecomment-7149938585) Closing — #322 fixes the same issue (#242) and was opened first. One thing I did not see covered there and worth carrying into review: while a legacy directory is stuck (its migration failing whole on an unreadable blob), an update to the container can still commit a fresh version holding only the submitted blobs, and the next scan then clears the old directory as done — the readable legacy blobs are lost. Refusing updates to that container until the migration goes through closes it.
@ -313,0 +316,4 @@
let Some(blob) = entry.file_name().to_str().and_then(decode) else {
continue;
};
let data = std::fs::read(entry.path()).ok()?;
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:16 UTC · original

P1 Badge Reject writes while a legacy migration is incomplete

When a blob is unreadable, this returns None, but Provider::open still succeeds and reads report BLOB_NOT_FOUND. If the title then submits an update, Update::submit commits a fresh v1 containing only the submitted blobs. The next containers() scan treats that version as a completed migration and deletes the legacy directory, losing even its readable, unmodified blobs. An isolated run with readable Data, unreadable Header, and an update writing New leaves only New; the parent preserves Data. Propagate the migration failure or reject writes to the affected container until migration succeeds instead of treating it as missing.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/383#discussion_r4688424547) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Reject writes while a legacy migration is incomplete** When a blob is unreadable, this returns `None`, but `Provider::open` still succeeds and reads report `BLOB_NOT_FOUND`. If the title then submits an update, `Update::submit` commits a fresh v1 containing only the submitted blobs. The next `containers()` scan treats that version as a completed migration and deletes the legacy directory, losing even its readable, unmodified blobs. An isolated run with readable `Data`, unreadable `Header`, and an update writing `New` leaves only `New`; the parent preserves `Data`. Propagate the migration failure or reject writes to the affected container until migration succeeds instead of treating it as missing. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:16 UTC · original
On crates/victory-hle/src/modules/xgamesave.rs line 1172 (outdated):

@@ -1143,6 +1152,46 @@ mod tests {
         assert_eq!((v.number, v.display.as_str()), (1, "Chapter 1"));
     }
 
+    /// A blob that cannot be read leaves the old directory whole: nothing
+    /// migrates (committing half the blobs would drop the rest), and a
+    /// later call with the file readable moves everything.
+    #[cfg(unix)]
+    #[test]
+    fn an_unreadable_blob_keeps_the_old_layout_for_a_retry() {
+        use std::os::unix::fs::PermissionsExt;
+        let saves = tempfile::tempdir().unwrap();
+        let root = saves.path().join(format!("{:016X}", xuser::XUID)).join("scid");
+        let old = root.join("Player");
+        std::fs::create_dir_all(&old).unwrap();
+        std::fs::write(old.join("Data"), b"data").unwrap();
+        let header = old.join("Header");
+        std::fs::write(&header, b"header").unwrap();
+        let mut perms = std::fs::metadata(&header).unwrap().permissions();
+        perms.set_mode(0);
+        std::fs::set_permissions(&header, perms).unwrap();
+        assert_eq!(std::fs::read(&header).unwrap_err().kind(), std::io::ErrorKind::PermissionDenied);

P2 Badge Make the permission fixture handle privileged Unix users

When this test runs with permission-bypassing privileges, such as root in a default Linux container, mode 000 does not prevent reading the file. Consequently, std::fs::read(&header) succeeds and unwrap_err() panics before migration is exercised. The extracted test reproducibly fails as root and passes as an unprivileged user. Run the permission-specific case without elevated access, skip it when access cannot be denied, or use deterministic read-failure injection.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/383#discussion_r4688424552) On `crates/victory-hle/src/modules/xgamesave.rs` line 1172 (outdated): ```diff @@ -1143,6 +1152,46 @@ mod tests { assert_eq!((v.number, v.display.as_str()), (1, "Chapter 1")); } + /// A blob that cannot be read leaves the old directory whole: nothing + /// migrates (committing half the blobs would drop the rest), and a + /// later call with the file readable moves everything. + #[cfg(unix)] + #[test] + fn an_unreadable_blob_keeps_the_old_layout_for_a_retry() { + use std::os::unix::fs::PermissionsExt; + let saves = tempfile::tempdir().unwrap(); + let root = saves.path().join(format!("{:016X}", xuser::XUID)).join("scid"); + let old = root.join("Player"); + std::fs::create_dir_all(&old).unwrap(); + std::fs::write(old.join("Data"), b"data").unwrap(); + let header = old.join("Header"); + std::fs::write(&header, b"header").unwrap(); + let mut perms = std::fs::metadata(&header).unwrap().permissions(); + perms.set_mode(0); + std::fs::set_permissions(&header, perms).unwrap(); + assert_eq!(std::fs::read(&header).unwrap_err().kind(), std::io::ErrorKind::PermissionDenied); ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Make the permission fixture handle privileged Unix users** When this test runs with permission-bypassing privileges, such as root in a default Linux container, mode `000` does not prevent reading the file. Consequently, `std::fs::read(&header)` succeeds and `unwrap_err()` panics before migration is exercised. The extracted test reproducibly fails as root and passes as an unprivileged user. Run the permission-specific case without elevated access, skip it when access cannot be denied, or use deterministic read-failure injection. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.