runtime: stop sizing the DirectStorage inflate buffer from CancellationTag #2121

Merged
Its3rr0rsWRLD merged 1 commit from upstream-pr/2129 into main 2026-11-25 01:27:23 +00:00
Its3rr0rsWRLD commented 2026-11-25 01:06:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-25T01:06:06Z.


Change

The DirectStorage stand-in (src/startup_stubs/xcrdapi.cpp) read request +0x38 as an uncompressed size and sized its inflate buffer from it. In the public DSTORAGE_REQUEST layout the two unions are 16 bytes each, which puts DestinationSize at +0x18, SourceSize at +0x30, IntermediateSize at +0x34 and CancellationTag (UINT64, "an arbitrary UINT64 number used for cancellation matching") at +0x38. The offsets the stand-in already uses for the other fields agree with that layout.

So the value at +0x38 is not a size. This also explains the observation on #1198 that the field "read as the uncompressed size" is 0 on the requests that exceed their destination: those requests carry no tag. A title that does set a tag would make the worker allocate and zero-fill up to 4 GiB per zlib request (twice that with BCPack), or fail the request with std::bad_alloc.

After this change:

  • a zlib-only request inflates into DestinationSize (the documented size of the final result); the existing 512 KiB retry for chunked streams is unchanged;
  • a zlib + BCPack request keeps the existing destination-based bound (2 * DestinationSize + 64 KiB) and raises it to IntermediateSize, the documented number of BCPack bytes, when that is larger.

Nothing else in request handling changes: the capacity check, the stream cache, the failure causes and the heartbeat are untouched.

Refs #1198

#1429 by @Holastor makes the same +0x34 / +0x38 correction as part of a larger change (interleaved chunked streams, EOF fallback, async gamesave reads), and was opened first. It is currently far behind main and conflicts in src/startup_stubs/xcrdapi.cpp. This PR is only the field correction and its fixture, on current main, so it can be reviewed on its own; #1429's streaming work is unaffected and can rebase on top of it.

Verification

Release build (cmake --preset release, MSVC, Windows 11) at this branch's commit on top of c580d904:

ctest --preset release --no-tests=error -R "storage|startup_stubs|startup_inflate|cpu_native_dstorage|startup_dstorage"
100% tests passed, 0 tests failed out of 20

That selection includes startup_storage_alloc_failure, startup_storage_failure_counts (+ control), startup_storage_page_end_counts (+ control), startup_storage_consumer_pair (+ control), startup_storage_worker_start, startup_storage_refusal_order, startup_dstorage_destination, startup_storage_directory_batch, startup_inflate, startup_stubs and cpu_native_dstorage.

Fail-first control: with src/startup_stubs/xcrdapi.cpp reverted to c580d904 and the updated test kept, startup_storage_alloc_failure fails with

a zlib request with a large CancellationTag did not succeed (hr 0x80004005)

and passes again with the change restored.

I did not run the Debug configuration or the pr preset.

Evidence and follow-up

tests/startup_storage_alloc_failure.cpp is the only fixture that depended on the old reading: it produced its allocation failure by writing 1.5 GiB at +0x38. It now

  • produces the same failure through IntermediateSize (+0x34) on a zlib + BCPack request, and
  • adds a zlib request that carries the same 1.5 GiB number as its CancellationTag under the job commit limit; it must complete with S_OK and the right bytes.

Other storage fixtures still write a size at +0x38 (startup_storage_consumer_pair, _failure_counts, _page_end_counts, _refusal_order, _worker_start). They pass unchanged because that value is no longer read; I left them alone to keep this PR to one behavior, and can drop those writes in a follow-up if preferred.

Limits and assumptions:

  • The layout comes from the public reference page only. In the one startup log I looked at, the twelve requests logged in full all had zero at +0x38..+0x3f, so this change did not alter that run; it removes a wrong read rather than fixing an observed failure.
  • Whether the console bounds IntermediateSize is not documented. The stand-in honours it as given; an unserviceable value fails that request and the worker keeps running, which is what the updated fixture checks.
  • This does not address the requests on #1198 whose zlib stream inflates to more than DestinationSize. What the console does with such a request is not publicly documented and this PR does not guess at it.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (none changed)
  • I did not include game files, dumps, distribution links or secrets.

This change was prepared by Claude Opus 5.5.

🤖 Generated with Claude Code

https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594743393 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2129). Originally posted by [Its3rr0rsWRLD](https://github.com/Its3rr0rsWRLD) on 2026-11-25T01:06:06Z. --- ## Change The DirectStorage stand-in (`src/startup_stubs/xcrdapi.cpp`) read request `+0x38` as an uncompressed size and sized its inflate buffer from it. In the public [`DSTORAGE_REQUEST`](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/structs/dstorage_request) layout the two unions are 16 bytes each, which puts `DestinationSize` at `+0x18`, `SourceSize` at `+0x30`, `IntermediateSize` at `+0x34` and `CancellationTag` (`UINT64`, "an arbitrary UINT64 number used for cancellation matching") at `+0x38`. The offsets the stand-in already uses for the other fields agree with that layout. So the value at `+0x38` is not a size. This also explains the observation on #1198 that the field "read as the uncompressed size" is 0 on the requests that exceed their destination: those requests carry no tag. A title that does set a tag would make the worker allocate and zero-fill up to 4 GiB per zlib request (twice that with BCPack), or fail the request with `std::bad_alloc`. After this change: - a zlib-only request inflates into `DestinationSize` (the documented size of the final result); the existing 512 KiB retry for chunked streams is unchanged; - a zlib + BCPack request keeps the existing destination-based bound (`2 * DestinationSize + 64 KiB`) and raises it to `IntermediateSize`, the documented number of BCPack bytes, when that is larger. Nothing else in request handling changes: the capacity check, the stream cache, the failure causes and the heartbeat are untouched. Refs #1198 ## Related work #1429 by @Holastor makes the same `+0x34` / `+0x38` correction as part of a larger change (interleaved chunked streams, EOF fallback, async gamesave reads), and was opened first. It is currently far behind `main` and conflicts in `src/startup_stubs/xcrdapi.cpp`. This PR is only the field correction and its fixture, on current `main`, so it can be reviewed on its own; #1429's streaming work is unaffected and can rebase on top of it. ## Verification Release build (`cmake --preset release`, MSVC, Windows 11) at this branch's commit on top of `c580d904`: ``` ctest --preset release --no-tests=error -R "storage|startup_stubs|startup_inflate|cpu_native_dstorage|startup_dstorage" 100% tests passed, 0 tests failed out of 20 ``` That selection includes `startup_storage_alloc_failure`, `startup_storage_failure_counts` (+ control), `startup_storage_page_end_counts` (+ control), `startup_storage_consumer_pair` (+ control), `startup_storage_worker_start`, `startup_storage_refusal_order`, `startup_dstorage_destination`, `startup_storage_directory_batch`, `startup_inflate`, `startup_stubs` and `cpu_native_dstorage`. Fail-first control: with `src/startup_stubs/xcrdapi.cpp` reverted to `c580d904` and the updated test kept, `startup_storage_alloc_failure` fails with ``` a zlib request with a large CancellationTag did not succeed (hr 0x80004005) ``` and passes again with the change restored. I did not run the Debug configuration or the `pr` preset. ## Evidence and follow-up `tests/startup_storage_alloc_failure.cpp` is the only fixture that depended on the old reading: it produced its allocation failure by writing 1.5 GiB at `+0x38`. It now - produces the same failure through `IntermediateSize` (`+0x34`) on a zlib + BCPack request, and - adds a zlib request that carries the same 1.5 GiB number as its `CancellationTag` under the job commit limit; it must complete with `S_OK` and the right bytes. Other storage fixtures still write a size at `+0x38` (`startup_storage_consumer_pair`, `_failure_counts`, `_page_end_counts`, `_refusal_order`, `_worker_start`). They pass unchanged because that value is no longer read; I left them alone to keep this PR to one behavior, and can drop those writes in a follow-up if preferred. Limits and assumptions: - The layout comes from the public reference page only. In the one startup log I looked at, the twelve requests logged in full all had zero at `+0x38..+0x3f`, so this change did not alter that run; it removes a wrong read rather than fixing an observed failure. - Whether the console bounds `IntermediateSize` is not documented. The stand-in honours it as given; an unserviceable value fails that request and the worker keeps running, which is what the updated fixture checks. - This does not address the requests on #1198 whose zlib stream inflates to more than `DestinationSize`. What the console does with such a request is not publicly documented and this PR does not guess at it. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. (none changed) - [x] I did not include game files, dumps, distribution links or secrets. This change was prepared by Claude Opus 5.5. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
upstream-sync closed this pull request 2026-11-25 02:01:51 +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!2121
No description provided.