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

Closed
github-bot wants to merge 2 commits from github-bot/gh-1141 into main AGit
Owner

@⁠TimIdle on GitHub · 2026-11-24 19:10 UTC · original
TimIdle:oldpr-9880-gamesave-quota → main · +100 −6 · 2 files · 2 commits · closed without merging

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

**@⁠TimIdle** on GitHub · 2026-11-24 19:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1141) `TimIdle:oldpr-9880-gamesave-quota` → `main` · +100 −6 · 2 files · 2 commits · closed without merging Claimed in the coordination issue as: OLD-9880 ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)) ### 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)
On NTFS "story" and "STORY" are one file. Since the rollback commit of #992, an
update holding both fails at the backup of the second name, after the first was
already applied, and returns E_GS_OUT_OF_LOCAL_STORAGE. Write and Delete now
refuse the second name with E_INVALIDARG, as they refuse an exact duplicate, so
an update holds one op per file. The case-alias checks expect that refusal and
compare the remaining quota with its value before the seed, since the rollback
checks leave their container behind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:40:00 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 19:13 UTC · original · approved these changes

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.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 19:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1141#pullrequestreview-6045703031) · **approved these changes** 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.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 19:33 UTC · original

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

**@⁠madhyn** on GitHub · 2026-11-24 19:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1141#issuecomment-7142261864) 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
Author
Owner

@⁠Deedlyy on GitHub · 2026-11-24 20:13 UTC · original

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

**@⁠Deedlyy** on GitHub · 2026-11-24 20:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1141#issuecomment-7143223912) **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
Author
Owner

@⁠TimIdle on GitHub · 2026-11-25 00:18 UTC · original

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** on GitHub · 2026-11-25 00:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1141#issuecomment-7148380845) 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.
github-bot closed this pull request 2026-11-26 11:42:22 +00:00
Author
Owner

@⁠TimIdle on GitHub · 2026-11-26 11:41 UTC · original

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

**@⁠TimIdle** on GitHub · 2026-11-26 11:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1141#issuecomment-7191041626) Closing this one, no review yet and CI is red. Will reopen if it is still needed.

Pull request closed

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