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

Manually merged
github merged 1 commit from gh-pr/2129/head into gh-pr/2129/base 2026-11-26 23:58:47 +00:00
Owner

@⁠Its3rr0rsWRLD on GitHub · 2026-11-25 01:06 UTC · original
Its3rr0rsWRLD:pr/dstorage-intermediate-size → main · +46 −34 · 2 files · 1 commits · merged 2026-11-25 01:27 UTC

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

**@⁠Its3rr0rsWRLD** on GitHub · 2026-11-25 01:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2129) `Its3rr0rsWRLD:pr/dstorage-intermediate-size` → `main` · +46 −34 · 2 files · 1 commits · merged 2026-11-25 01:27 UTC ## 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
The stand-in read request +0x38 as an uncompressed size and sized the
inflate buffer from it. The public DSTORAGE_REQUEST layout has SourceSize
at +0x30, IntermediateSize at +0x34 and CancellationTag (UINT64, "an
arbitrary number used for cancellation matching") at +0x38, so a title
that sets a tag made the worker allocate and zero-fill up to 4 GiB per
zlib request, or fail the request with std::bad_alloc.

A zlib-only request now inflates into DestinationSize (the existing
512 KiB retry still covers chunked streams). A zlib + BCPack request
keeps the destination-based bound and raises it to IntermediateSize,
the documented size of the BCPack data, when that is larger.

startup_storage_alloc_failure now drives the allocation failure through
IntermediateSize on a zlib + BCPack request, and adds a zlib request
that carries the same 1.5 GiB number as its CancellationTag under the
commit limit: it must succeed. With the old sizing that request fails.

Layout: https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/structs/dstorage_request

Refs #1198

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:58:46 +00:00
github manually merged commit f3f34f3d28 into gh-pr/2129/base 2026-11-26 23:58:47 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.