XGameSave: validate container quota and sanitize blob URL encoding #1420

Open
slopgobblercobbler wants to merge 1 commit from upstream-pr/1430 into main
slopgobblercobbler commented 2026-11-24 15:53:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T15:53:09Z.


Summary

Hardens XGameSave storage against malformed inputs, overlong names, quota overflow, and non-ASCII URL decoding panics:

  1. Safe URL percent-decoding (crates/xcl/src/hle/xgameruntime/gamesave.rs):
    • Replaced &file[i + 1..i + 3] string slicing in dec() with byte-level ASCII hex validation (hex_val()), preventing UTF-8 character boundary slicing panics on filenames containing non-ASCII characters following % (e.g. %€, %ü) and rejecting non-hex characters.
  2. Windows reserved device name escaping in enc():
    • Added is_reserved_device_name() extending DOS device protection to "CONIN$", "CONOUT$", and "CLOCK$" alongside "CON", "PRN", "AUX", "NUL", "COM0-9", and "LPT0-9".
  3. Blob name validation & bounds:
    • Enforced valid_blob_name(&n): rejects empty names ("") and overlong names (> 1024 bytes) in XGameSaveSubmitBlobWrite, XGameSaveSubmitBlobDelete, and names_of with E_INVALIDARG.
  4. Blob size limits:
    • Enforced GS_MAX_BLOB_SIZE = 16 << 20 (16 MiB) in XGameSaveSubmitBlobWrite, returning E_GS_UPDATE_TOO_BIG (0x80830005).
  5. Container quota validation:
    • Added calculate_projected_quota() in apply() under SAVE_MUTATION: validates projected total across the provider root against QUOTA (256 MiB), folding multiple operations per blob and netting existing on-disk sizes. Returns E_GS_QUOTA_EXCEEDED (0x80830006) atomically before modifying or deleting any files on disk.
  6. Synchronization & null-pointer safety:
    • Synchronized XGameSaveGetRemainingQuota with SAVE_MUTATION lock to prevent reading mid-mutation, and validated non-null quota out pointer in XGameSaveGetRemainingQuotaResult returning E_INVALIDARG.

Changes

  • crates/xcl/src/hle/xgameruntime/gamesave.rs:
    • dec(): byte-level hex validation avoiding slice panic on non-ASCII characters.
    • enc(): extended reserved Windows device name checks.
    • apply(): atomic projected quota check before disk mutation.
    • Unit tests: added 4 synthetic unit tests covering UTF-8 percent-decoding, Windows special device names, overlong blob name rejection, and atomic quota enforcement.

Tested

  • Windows 11 x64, Rust 1.85+ stable (MSVC).
  • cargo test -p xcl -- gamesave: 14 passed, 0 failed (100% pass rate).
  • Sabotage tested: verifying invalid percent-encoding returns original strings without panic.
  • Zero trailing whitespace, GPL-2.0-only compliant, zero game data/keys.

Not Tested

  • Real title save synchronization (synthetic in-memory / local folder tests only).

AI Use

Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity

<!-- greyfinch-sync:ivall/xcl:issue:5475595073 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1430). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-24T15:53:09Z. --- ## Summary Hardens XGameSave storage against malformed inputs, overlong names, quota overflow, and non-ASCII URL decoding panics: 1. **Safe URL percent-decoding (`crates/xcl/src/hle/xgameruntime/gamesave.rs`)**: - Replaced `&file[i + 1..i + 3]` string slicing in `dec()` with byte-level ASCII hex validation (`hex_val()`), preventing UTF-8 character boundary slicing panics on filenames containing non-ASCII characters following `%` (e.g. `%€`, `%ü`) and rejecting non-hex characters. 2. **Windows reserved device name escaping in `enc()`**: - Added `is_reserved_device_name()` extending DOS device protection to `"CONIN$"`, `"CONOUT$"`, and `"CLOCK$"` alongside `"CON"`, `"PRN"`, `"AUX"`, `"NUL"`, `"COM0-9"`, and `"LPT0-9"`. 3. **Blob name validation & bounds**: - Enforced `valid_blob_name(&n)`: rejects empty names (`""`) and overlong names (> 1024 bytes) in `XGameSaveSubmitBlobWrite`, `XGameSaveSubmitBlobDelete`, and `names_of` with `E_INVALIDARG`. 4. **Blob size limits**: - Enforced `GS_MAX_BLOB_SIZE = 16 << 20` (16 MiB) in `XGameSaveSubmitBlobWrite`, returning `E_GS_UPDATE_TOO_BIG` (0x80830005). 5. **Container quota validation**: - Added `calculate_projected_quota()` in `apply()` under `SAVE_MUTATION`: validates projected total across the provider root against `QUOTA` (256 MiB), folding multiple operations per blob and netting existing on-disk sizes. Returns `E_GS_QUOTA_EXCEEDED` (0x80830006) atomically before modifying or deleting any files on disk. 6. **Synchronization & null-pointer safety**: - Synchronized `XGameSaveGetRemainingQuota` with `SAVE_MUTATION` lock to prevent reading mid-mutation, and validated non-null `quota` out pointer in `XGameSaveGetRemainingQuotaResult` returning `E_INVALIDARG`. ## Changes - `crates/xcl/src/hle/xgameruntime/gamesave.rs`: - `dec()`: byte-level hex validation avoiding slice panic on non-ASCII characters. - `enc()`: extended reserved Windows device name checks. - `apply()`: atomic projected quota check before disk mutation. - Unit tests: added 4 synthetic unit tests covering UTF-8 percent-decoding, Windows special device names, overlong blob name rejection, and atomic quota enforcement. ## Tested - Windows 11 x64, Rust 1.85+ stable (MSVC). - `cargo test -p xcl -- gamesave`: 14 passed, 0 failed (100% pass rate). - Sabotage tested: verifying invalid percent-encoding returns original strings without panic. - Zero trailing whitespace, GPL-2.0-only compliant, zero game data/keys. ## Not Tested - Real title save synchronization (synthetic in-memory / local folder tests only). ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
futurepro62 commented 2026-11-24 16:07:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:58:30Z.


Full-suite run, since this PR has no test report yet. Tested exact head d820ec8 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 755 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: url_encoding_safety_dec_non_ascii_and_malformed_percent_does_not_panic, url_encoding_device_names_and_windows_specials, blob_name_bounds_and_empty_validation, container_quota_validation_enforces_limit_and_atomicity.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 755 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7136918797 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1430#issuecomment-7136918797). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T15:58:30Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `d820ec8` (on its base `930e8b4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **755 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `url_encoding_safety_dec_non_ascii_and_malformed_percent_does_not_panic`, `url_encoding_device_names_and_windows_specials`, `blob_name_bounds_and_empty_validation`, `container_quota_validation_enforces_limit_and_atomicity`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **755 passed, 0 failed, 41 ignored**, no skips. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
gut0to commented 2026-11-24 18:59:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:59:15Z.

Review: COMMENTED


CONTRIBUTING.md requires paired real-title scripts/smoke.ps1 runs for this runtime change, with main and this head tested on the same title and duration. The current description says real-title execution was not tested and has no regression blocks. Please add the required pair before merge, documenting if the title does not reach XGameSave. AI-assisted review; I checked the description against the guide.

<!-- greyfinch-sync:ivall/xcl:review:6045471366 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1430#pullrequestreview-6045471366). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-24T18:59:15Z. **Review:** COMMENTED --- CONTRIBUTING.md requires paired real-title `scripts/smoke.ps1` runs for this runtime change, with `main` and this head tested on the same title and duration. The current description says real-title execution was not tested and has no regression blocks. Please add the required pair before merge, documenting if the title does not reach XGameSave. AI-assisted review; I checked the description against the guide.
DavidM1911 commented 2026-11-24 19:07:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:52:19Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7141269259 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1430#issuecomment-7141269259). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T18:52:19Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Toons29 commented 2026-11-25 04:10:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:30:22Z.


Regression run of d820ec84 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: d820ec846f05b9f3c117b1d33393344be622580c
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1635 (PresentX 1635)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14685 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 99 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

<!-- greyfinch-sync:ivall/xcl:comment:7151977218 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1430#issuecomment-7151977218). Originally posted by [Toons29](https://github.com/Toons29) on 2026-11-25T03:30:22Z. --- Regression run of `d820ec84` on the retail title, for this PR's **Regression run** section. Both blocks are from `scripts/smoke.ps1` as printed, not edited: `main` on `4178e888`, this PR on its head commit with no uncommitted changes, same title and time. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14831 MB ``` ``` xcl-smoke v1 commit: d820ec846f05b9f3c117b1d33393344be622580c gpu: AMD Radeon RX 9070 title: game.exe seconds: 60 exit: 0x0 frames shown: 1635 (PresentX 1635) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14685 MB ``` Against the limits in CONTRIBUTING.md: 101 % of `main`'s frames, 99 % of its peak commit, no crash, no device removal. AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, `cargo build --release -p xcl`, 60 s, `XCL_NETWORK=0`. This is a regression check only: it does not show whether the run reaches the code this PR changes. AI use: Claude Code (Claude Opus 5.5) built both trees and ran `scripts/smoke.ps1`; I checked the blocks before posting.
github-actions[bot] commented 2026-11-28 08:01:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T08:01:54Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7236316396 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1430#issuecomment-7236316396). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T08:01:54Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:43:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:43:26Z.


Triage (#1607) – head d820ec8

The dec() change in gamesave.rs (decode %XX from the bytes instead of slicing the str, so a multi-byte character after '%' no longer panics) is the same fix as #448, which was opened first, does only that and has a test enumerating such a container; please drop that hunk and its test here.
The rest (per-blob 16 MiB limit with E_GS_UPDATE_TOO_BIG, blob-name length check, projected-quota check in apply() returning E_GS_QUOTA_EXCEEDED, CONIN$/CONOUT$/CLOCK$ as reserved names) is not made by another open PR. These are four separate changes in one PR; per CONTRIBUTING.md they would be easier to review split. In the GDK, E_GS_UPDATE_TOO_BIG applies to the total size of one update, not to each blob, so the 17 x 16 MiB update in the test would already fail there before the quota check.
The PR conflicts with main.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302069783 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1430#issuecomment-7302069783). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:43:26Z. --- **Triage (#1607)** – head d820ec8 The dec() change in gamesave.rs (decode %XX from the bytes instead of slicing the str, so a multi-byte character after '%' no longer panics) is the same fix as #448, which was opened first, does only that and has a test enumerating such a container; please drop that hunk and its test here. The rest (per-blob 16 MiB limit with E_GS_UPDATE_TOO_BIG, blob-name length check, projected-quota check in apply() returning E_GS_QUOTA_EXCEEDED, CONIN$/CONOUT$/CLOCK$ as reserved names) is not made by another open PR. These are four separate changes in one PR; per CONTRIBUTING.md they would be easier to review split. In the GDK, E_GS_UPDATE_TOO_BIG applies to the total size of one update, not to each blob, so the 17 x 16 MiB update in the test would already fail there before the quota check. The PR conflicts with main. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1430:upstream-pr/1430'
git switch 'upstream-pr/1430'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1430'
git switch 'upstream-pr/1430'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1430'
git switch 'upstream-pr/1430'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1430'
git switch 'main'
git merge --squash 'upstream-pr/1430'
git switch 'main'
git merge --ff-only 'upstream-pr/1430'
git switch 'main'
git merge 'upstream-pr/1430'
git push origin 'main'
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
xcl-dev/xcl!1420
No description provided.