OLD-9880: XGameSave commit() counts a case-aliased blob once, so the quota cannot underflow (carries #147) #1141

Closed
TimIdle wants to merge 2 commits from upstream-pr/1141 into main
TimIdle commented 2026-11-24 19:10:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TimIdle on 2026-11-24T19:10:35Z.


Claimed in the coordination issue as: OLD-9880 (claim)

What and why

This carries forward old-pr/9880 by @ChalanaGimhanaX (draft #147). Their commit is cherry-picked onto main with the author kept, and rebased over #992. A second commit by me covers what #992 changed.

encode_name keeps ASCII letters as they are, so the blobs story and STORY are the same file on NTFS. commit() subtracted the existing file's size once per name. An update that names that file twice subtracted it twice, the uint64_t total wrapped, and a small delete failed with E_GS_QUOTA_EXCEEDED.

The fix subtracts each on-disk file once (fs::equivalent), clamps the subtraction at 0 and saturates the addition.

#992 then gave commit() a rollback path. With both names in one update, the second name's backup fails after the first was applied, and the update returns E_GS_OUT_OF_LOCAL_STORAGE. So the second commit makes XGameSaveSubmitBlobWrite and XGameSaveSubmitBlobDelete refuse a name that differs from one already in the update only in case, with E_INVALIDARG, as they already refuse an exact duplicate. The case-alias checks now expect that refusal. They compare the remaining quota with its value before the seed, because the rollback checks of #992 leave their container behind.

Tested

Native Windows 11 10.0.26300 (NTFS), MSVC 19.44, RelWithDebInfo, on main 364ab4e plus the two commits.

Check Result
xgameruntime_gamesave_test with both commits 88 checks, 0 failures
xgameruntime_gamesave_test with main's xgameruntime_gamesave.cpp 88 checks, 7 failures, starting with FAIL a delete of "STORY" after one of "story" in the same update is refused as the same blob
xgameruntime_gamesave_test with only the first commit's xgameruntime_gamesave.cpp 88 checks, 7 failures (the same 7)
full ctest -j 6 316 of 316 passed, gameinput disabled.

Not covered: a name is still kept in the case it was first written in. Whether names should be case-folded on disk is a separate question.

GPUs tested: n/a (no GPU code)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator rule here.)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5478619575 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1141). Originally posted by [TimIdle](https://github.com/TimIdle) on 2026-11-24T19:10:35Z. --- Claimed in the coordination issue as: OLD-9880 ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7141481946)) ### What and why This carries forward `old-pr/9880` by @ChalanaGimhanaX (draft #147). Their commit is cherry-picked onto `main` with the author kept, and rebased over #992. A second commit by me covers what #992 changed. `encode_name` keeps ASCII letters as they are, so the blobs `story` and `STORY` are the same file on NTFS. `commit()` subtracted the existing file's size once per name. An update that names that file twice subtracted it twice, the `uint64_t` total wrapped, and a small delete failed with `E_GS_QUOTA_EXCEEDED`. The fix subtracts each on-disk file once (`fs::equivalent`), clamps the subtraction at 0 and saturates the addition. #992 then gave `commit()` a rollback path. With both names in one update, the second name's backup fails after the first was applied, and the update returns `E_GS_OUT_OF_LOCAL_STORAGE`. So the second commit makes `XGameSaveSubmitBlobWrite` and `XGameSaveSubmitBlobDelete` refuse a name that differs from one already in the update only in case, with `E_INVALIDARG`, as they already refuse an exact duplicate. The case-alias checks now expect that refusal. They compare the remaining quota with its value before the seed, because the rollback checks of #992 leave their container behind. ### Tested Native Windows 11 10.0.26300 (NTFS), MSVC 19.44, RelWithDebInfo, on `main` `364ab4e` plus the two commits. | Check | Result | |---|---| | `xgameruntime_gamesave_test` with both commits | 88 checks, 0 failures | | `xgameruntime_gamesave_test` with `main`'s `xgameruntime_gamesave.cpp` | 88 checks, 7 failures, starting with `FAIL a delete of "STORY" after one of "story" in the same update is refused as the same blob` | | `xgameruntime_gamesave_test` with only the first commit's `xgameruntime_gamesave.cpp` | 88 checks, 7 failures (the same 7) | | full `ctest -j 6` | 316 of 316 passed, `gameinput` disabled. | Not covered: a name is still kept in the case it was first written in. Whether names should be case-folded on disk is a separate question. GPUs tested: n/a (no GPU code) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator rule here.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
abnalstlll-byte commented 2026-11-24 19:13:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T19:13:52Z.

Review: APPROVED


Reviewed and verified. Resolves unsigned uint64_t quota underflow in xgameruntime_gamesave.cpp:commit() when case-aliased blob names (e.g., story vs STORY) target the same on-disk NTFS file. Deduplicating via fs::equivalent, clamping subtraction at 0, and saturating addition prevents false E_GS_QUOTA_EXCEEDED errors. Verified with xgameruntime_gamesave_test (66/66 checks PASS). 100% clean-room.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045703031 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1141#pullrequestreview-6045703031). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T19:13:52Z. **Review:** APPROVED --- Reviewed and verified. Resolves unsigned `uint64_t` quota underflow in `xgameruntime_gamesave.cpp:commit()` when case-aliased blob names (e.g., `story` vs `STORY`) target the same on-disk NTFS file. Deduplicating via `fs::equivalent`, clamping subtraction at 0, and saturating addition prevents false `E_GS_QUOTA_EXCEEDED` errors. Verified with `xgameruntime_gamesave_test` (66/66 checks PASS). 100% clean-room.
madhyn commented 2026-11-24 19:33:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T19:33:12Z.


Tested 31e6daf74 on Arch Linux + Wine 11.22 (clang-cl + xwin cross-build):

  • ctest --test-dir runtime/build/win -R "^xgameruntime_gamesave$" --output-on-failure: Passed (5.37 s)

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142261864 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1141#issuecomment-7142261864). Originally posted by [madhyn](https://github.com/madhyn) on 2026-11-24T19:33:12Z. --- Tested `31e6daf74` on Arch Linux + Wine 11.22 (clang-cl + xwin cross-build): - `ctest --test-dir runtime/build/win -R "^xgameruntime_gamesave$" --output-on-failure`: **Passed** (5.37 s) AI-assisted: yes
Deedlyy commented 2026-11-24 20:13:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:13:51Z.


Recommendation: [MERGE]

Reasoning: Carries #147: XGameSave commit() counts a case-aliased blob (story vs STORY, the same file on NTFS) once, so the quota can't underflow. Small fix with a test. Verified on Wine by madhyn. It conflicts with #992 in commit(), so whichever lands second needs a rebase. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 4/10

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143223912 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1141#issuecomment-7143223912). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:13:51Z. --- **Recommendation:** [MERGE] **Reasoning:** Carries #147: `XGameSave` `commit()` counts a case-aliased blob (`story` vs `STORY`, the same file on NTFS) once, so the quota can't underflow. Small fix with a test. Verified on Wine by madhyn. It conflicts with #992 in `commit()`, so whichever lands second needs a rebase. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 4/10
TimIdle commented 2026-11-25 00:18:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TimIdle on 2026-11-25T00:18:59Z.


Rebased onto main after #992 landed. The rollback path of #992 made an update that holds story and STORY fail at the backup of the second name, so this PR's own checks failed after the rebase. I added a second commit: XGameSaveSubmitBlobWrite and XGameSaveSubmitBlobDelete now refuse a name that differs from one already in the update only in case, with E_INVALIDARG, as they refuse an exact duplicate. The description has the new results.

@madhyn thank you for the Wine run. It was on 31e6daf, before this change, so the new head has not had a second run yet.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7148380845 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1141#issuecomment-7148380845). Originally posted by [TimIdle](https://github.com/TimIdle) on 2026-11-25T00:18:59Z. --- Rebased onto `main` after #992 landed. The rollback path of #992 made an update that holds `story` and `STORY` fail at the backup of the second name, so this PR's own checks failed after the rebase. I added a second commit: `XGameSaveSubmitBlobWrite` and `XGameSaveSubmitBlobDelete` now refuse a name that differs from one already in the update only in case, with `E_INVALIDARG`, as they refuse an exact duplicate. The description has the new results. @madhyn thank you for the Wine run. It was on `31e6daf`, before this change, so the new head has not had a second run yet.
TimIdle commented 2026-11-26 11:41:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TimIdle on 2026-11-26T11:41:16Z.


Closing this one, no review yet and CI is red. Will reopen if it is still needed.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7191041626 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1141#issuecomment-7191041626). Originally posted by [TimIdle](https://github.com/TimIdle) on 2026-11-26T11:41:16Z. --- Closing this one, no review yet and CI is red. Will reopen if it is still needed.

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
ProjectLeonida/mandy!1141
No description provided.