runtime: reject a null blob name in XGameSaveReadBlobData #1554

Merged
RenzoWit35 merged 1 commit from upstream-pr/1561 into main 2026-11-24 14:12:42 +00:00
RenzoWit35 commented 2026-11-24 14:00:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T14:00:17Z.


Change

src/xgameruntime_shim.cpp is the fixture-only XGameRuntime shim. Its XGameSaveReadBlobData implementation (game_save_read_blob_data) refused a null name list with E_INVALIDARG, but passed each element of the list unchecked to find_blob, which calls std::strcmp(blob.name, name) for every live blob of the container. A null element was therefore dereferenced as soon as the container held one live blob: an access violation inside a noexcept function, raised while the shim's shared lock was held.

  • The function now checks the requested entries of the list next to its existing argument check, before the lock is taken, and returns E_INVALIDARG for a null entry. *count_of_blobs stays 0 and nothing is written to the caller's buffer. The export wrapper records the result in the shim log like every other return of this function.
  • E_INVALIDARG was chosen because the function already returns it for its other bad arguments and because the write path (XGameSaveSubmitBlobWrite, through valid_blob_name) refuses a null name with the same code. What the GDK implementation returns for a null entry was not verified.
  • Unchanged: empty and over-long names cannot match a blob and still give HRESULT_FROM_WIN32(ERROR_NOT_FOUND). No other validation was added.
  • Two consequences of checking before the lock, both from reading the code and not covered by a test: a null entry read from a container without any live blob used to give ERROR_NOT_FOUND (strcmp was never reached) and now gives E_INVALIDARG; a null entry combined with a closed or expired container handle now gives E_INVALIDARG instead of E_HANDLE / E_GS_HANDLE_EXPIRED, the same order the function already uses for a null buffer.

The input needs a live blob to show the defect, which is why the test reads from the container that already holds player.bin.

docs/experiments.md does not list the refused inputs of this call, so it is not changed.

Verification

Environment: Windows 11 x64, VS Build Tools 2026 (MSVC 14.51), Windows SDK 26100, Ninja, dev preset (Debug), Python 3.14.5. Base: origin/main at 60c72330.

Regression check, added to the existing tests/xgameruntime_contracts_check.cpp (test xgameruntime_contracts, no new target): after player.bin is committed to slot-a, it calls XGameSaveReadBlobData with {nullptr} (count 1) and with {"player.bin", nullptr} (count 2) into a zeroed 512-byte buffer and requires E_INVALIDARG, count == 0 and an all-zero buffer. The XGameSaveCreateContainer call that follows takes the exclusive lock, so a leaked shared lock would hang the test (30 s timeout). The log scan now also requires an XGameSaveReadBlobData entry with E_INVALIDARG, next to the existing ERROR_NOT_FOUND control, and the expected log length goes from 34 to 36 entries (ring capacity 64, test buffer 48).

Commands, from <repo> in PowerShell:

. .\tools\dev.ps1; cmake --preset dev -B out/build/dev -DINTAKE_PYTHON=<repo>/out/pe-env/Scripts/python.exe
cmake --build out/build/dev --target xgameruntime_contracts_check xgameruntime_shim xmem_shim xgameruntime_shim_check xgameruntime_pls_xpackage_check xgameruntime_identity_check xgameruntime_preflight_exe d3d12_xs_shim --parallel 3
ctest --test-dir out/build/dev --no-tests=error -R '^xgameruntime_' -V
out\pe-env\Scripts\python.exe -B tests/xgameruntime_table_check.py

Observed with the change:

  • xgameruntime contracts: user=implemented game-save=implemented reopen=ok stale=E_GS_HANDLE_EXPIRED negative=E_NOTIMPL x2 PASS
  • 100% tests passed, 0 tests failed out of 5 (xgameruntime_thunks, xgameruntime_contracts, xgameruntime_pls_xpackage, xgameruntime_identity, xgameruntime_preflight_stub_refused)
  • xgameruntime table: exports=28 ... duplicate_control=detected PASS

Negative control: the new check built against the unmodified shim source (git checkout origin/main -- src/xgameruntime_shim.cpp, rebuild xgameruntime_shim, ctest --test-dir out/build/dev --no-tests=error -R '^xgameruntime_contracts$' -V):

  • 1/1 Test #50: xgameruntime_contracts ...........***Exception: SegFault
  • 0% tests passed, 1 tests failed out of 1, 50 - xgameruntime_contracts (SEGFAULT)
  • Running xgameruntime_contracts_check.exe directly with the same three arguments ends with exit code 0xC0000005 and prints nothing. The call is not guarded in the test, so the failure on the old code is the crash itself.

After restoring the fix and rebuilding, the five tests pass again as listed above.

Rebased onto origin/main at a3633d4d before opening this pull request and re-run there: shim and check rebuilt, xgameruntime_contracts, xgameruntime_thunks, xgameruntime_pls_xpackage and xgameruntime_identity passed.

Not run: the full test suite, the pr preset, a Release build, GPU and hardware tests. The two code-reading consequences listed under Change were not exercised.

Evidence and follow-up

No open pull request touches src/xgameruntime_shim.cpp, tests/xgameruntime_contracts_check.cpp or any other path containing xgameruntime (checked with gh pr list --state open --limit 200 --json number,title,files, 47 open pull requests at the time). A search of open issues and pull requests for XGameSaveReadBlobData returned nothing. No issue is linked.

The crash needs a caller that passes a null entry in the name list; the existing fixtures never did, so this is a robustness fix for the shim's own contract, not a change observed to matter for any program.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6583485369 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1561). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T14:00:17Z. --- ## Change `src/xgameruntime_shim.cpp` is the fixture-only XGameRuntime shim. Its `XGameSaveReadBlobData` implementation (`game_save_read_blob_data`) refused a null name list with `E_INVALIDARG`, but passed each element of the list unchecked to `find_blob`, which calls `std::strcmp(blob.name, name)` for every live blob of the container. A null element was therefore dereferenced as soon as the container held one live blob: an access violation inside a `noexcept` function, raised while the shim's shared lock was held. - The function now checks the `requested` entries of the list next to its existing argument check, before the lock is taken, and returns `E_INVALIDARG` for a null entry. `*count_of_blobs` stays 0 and nothing is written to the caller's buffer. The export wrapper records the result in the shim log like every other return of this function. - `E_INVALIDARG` was chosen because the function already returns it for its other bad arguments and because the write path (`XGameSaveSubmitBlobWrite`, through `valid_blob_name`) refuses a null name with the same code. What the GDK implementation returns for a null entry was not verified. - Unchanged: empty and over-long names cannot match a blob and still give `HRESULT_FROM_WIN32(ERROR_NOT_FOUND)`. No other validation was added. - Two consequences of checking before the lock, both from reading the code and not covered by a test: a null entry read from a container without any live blob used to give `ERROR_NOT_FOUND` (`strcmp` was never reached) and now gives `E_INVALIDARG`; a null entry combined with a closed or expired container handle now gives `E_INVALIDARG` instead of `E_HANDLE` / `E_GS_HANDLE_EXPIRED`, the same order the function already uses for a null buffer. The input needs a live blob to show the defect, which is why the test reads from the container that already holds `player.bin`. `docs/experiments.md` does not list the refused inputs of this call, so it is not changed. ## Verification Environment: Windows 11 x64, VS Build Tools 2026 (MSVC 14.51), Windows SDK 26100, Ninja, `dev` preset (Debug), Python 3.14.5. Base: `origin/main` at `60c72330`. Regression check, added to the existing `tests/xgameruntime_contracts_check.cpp` (test `xgameruntime_contracts`, no new target): after `player.bin` is committed to `slot-a`, it calls `XGameSaveReadBlobData` with `{nullptr}` (count 1) and with `{"player.bin", nullptr}` (count 2) into a zeroed 512-byte buffer and requires `E_INVALIDARG`, `count == 0` and an all-zero buffer. The `XGameSaveCreateContainer` call that follows takes the exclusive lock, so a leaked shared lock would hang the test (30 s timeout). The log scan now also requires an `XGameSaveReadBlobData` entry with `E_INVALIDARG`, next to the existing `ERROR_NOT_FOUND` control, and the expected log length goes from 34 to 36 entries (ring capacity 64, test buffer 48). Commands, from `<repo>` in PowerShell: ```powershell . .\tools\dev.ps1; cmake --preset dev -B out/build/dev -DINTAKE_PYTHON=<repo>/out/pe-env/Scripts/python.exe cmake --build out/build/dev --target xgameruntime_contracts_check xgameruntime_shim xmem_shim xgameruntime_shim_check xgameruntime_pls_xpackage_check xgameruntime_identity_check xgameruntime_preflight_exe d3d12_xs_shim --parallel 3 ctest --test-dir out/build/dev --no-tests=error -R '^xgameruntime_' -V out\pe-env\Scripts\python.exe -B tests/xgameruntime_table_check.py ``` Observed with the change: - `xgameruntime contracts: user=implemented game-save=implemented reopen=ok stale=E_GS_HANDLE_EXPIRED negative=E_NOTIMPL x2 PASS` - `100% tests passed, 0 tests failed out of 5` (`xgameruntime_thunks`, `xgameruntime_contracts`, `xgameruntime_pls_xpackage`, `xgameruntime_identity`, `xgameruntime_preflight_stub_refused`) - `xgameruntime table: exports=28 ... duplicate_control=detected PASS` Negative control: the new check built against the unmodified shim source (`git checkout origin/main -- src/xgameruntime_shim.cpp`, rebuild `xgameruntime_shim`, `ctest --test-dir out/build/dev --no-tests=error -R '^xgameruntime_contracts$' -V`): - `1/1 Test #50: xgameruntime_contracts ...........***Exception: SegFault` - `0% tests passed, 1 tests failed out of 1`, `50 - xgameruntime_contracts (SEGFAULT)` - Running `xgameruntime_contracts_check.exe` directly with the same three arguments ends with exit code `0xC0000005` and prints nothing. The call is not guarded in the test, so the failure on the old code is the crash itself. After restoring the fix and rebuilding, the five tests pass again as listed above. Rebased onto `origin/main` at `a3633d4d` before opening this pull request and re-run there: shim and check rebuilt, `xgameruntime_contracts`, `xgameruntime_thunks`, `xgameruntime_pls_xpackage` and `xgameruntime_identity` passed. Not run: the full test suite, the `pr` preset, a Release build, GPU and hardware tests. The two code-reading consequences listed under Change were not exercised. ## Evidence and follow-up No open pull request touches `src/xgameruntime_shim.cpp`, `tests/xgameruntime_contracts_check.cpp` or any other path containing `xgameruntime` (checked with `gh pr list --state open --limit 200 --json number,title,files`, 47 open pull requests at the time). A search of open issues and pull requests for `XGameSaveReadBlobData` returned nothing. No issue is linked. The crash needs a caller that passes a null entry in the name list; the existing fixtures never did, so this is a robustness fix for the shim's own contract, not a change observed to matter for any program. AI-assisted.
upstream-sync closed this pull request 2026-11-24 15:02:00 +00:00
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
R0Y00/Xbox2Windows!1554
No description provided.