startup: support DirectStorage zlib requests exceeding destination size #1167

Closed
github-bot wants to merge 5 commits from gh-pr/1167/head into gh-pr/1167/base
Owner

@⁠Holastor on GitHub · 2026-11-24 02:17 UTC · original
Holastor:fix/dstorage-zlib-64k → main · +9953 −1 · 39 files · 5 commits · closed without merging

Refs #1144.

Problem

In src/startup_stubs/xcrdapi.cpp, zlib decompression requests failed when an archive stream uncompressed to more than 64 KiB. The standalone decompressor x2w_inflate::inflate_zlib operates in a single pass into a fixed linear buffer. Because the runtime sized the output buffer strictly to destination_size read from request + 0x18 (which is 0x10000 = 64 KiB for a single tile/page target), any stream exceeding 64 KiB ran out of buffer space, returning false and causing outcome = "zlib failed" with E_FAIL.

Furthermore, for requests targeting physical page tokens (options & (1ull << 21)), queue_enqueue_request computed page token count using destination_size (64 KiB), capturing only 1 token and dropping subsequent page tokens for multi-page requests.

Change

  1. In src/startup_stubs/xcrdapi.cpp:
    • Read uncompressed_size from request + 0x38 (matching Microsoft DirectStorage specification, where UncompressedSize can exceed Destination.Size for non-memory destinations).
    • In queue_enqueue_request: compute size = (uncompressed_size > destination_size) ? uncompressed_size : destination_size so all physical page tokens are retained in entry.tokens.
    • In execute_request: size decompression buffer to std::max(destination_size, uncompressed_size). If decompression requires more space (e.g. if uncompressed_size is unset), expand dynamically up to 512 KiB.
    • Bound destination writes to destination_size, ensuring buffer safety.
  2. In tests/dstorage_rfc1950_check.cpp:
    • Added test scenarios large_128k (128 KiB) and large_256k (256 KiB) testing full RFC 1950 stream decompression through the DirectStorage file queue with exact byte verification.
    • Added negative control overflow_64k: a 128 KiB stream submitted to a 64 KiB destination buffer. Verifies that decompression rejects the oversized payload with 0x8007000d (ERROR_INVALID_DATA), preserves all sentinel bytes without buffer overrun, and reports completion status 0x8007000d.

Verification

  • Windows 11 Pro x64 (build 26100), MSVC 19.51 (VS 2026 Developer PowerShell), DirectStorage SDK 1.3.0, zlib 1.3.1.
  • release preset:
    ctest --preset release --no-tests=error -R '^dstorage_rfc1950_' -V (9/9 pass, 0.17s)
    ctest --preset release --no-tests=error -R '^startup_stubs$' -V (pass, 0.09s)
  • dev preset:
    ctest --preset dev --no-tests=error -R '^dstorage_rfc1950_' -V (9/9 pass, 0.18s)
    ctest --preset dev --no-tests=error -R '^startup_stubs$' -V (pass, 0.10s)
  • Linters:
    tests/docs_links_check.py (16 files, 254 links) and tests/bidi_controls_check.py (973 files) pass with 0 errors.
**@⁠Holastor** on GitHub · 2026-11-24 02:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1167) `Holastor:fix/dstorage-zlib-64k` → `main` · +9953 −1 · 39 files · 5 commits · closed without merging Refs #1144. ## Problem In `src/startup_stubs/xcrdapi.cpp`, zlib decompression requests failed when an archive stream uncompressed to more than 64 KiB. The standalone decompressor `x2w_inflate::inflate_zlib` operates in a single pass into a fixed linear buffer. Because the runtime sized the output buffer strictly to `destination_size` read from `request + 0x18` (which is `0x10000` = 64 KiB for a single tile/page target), any stream exceeding 64 KiB ran out of buffer space, returning `false` and causing `outcome = "zlib failed"` with `E_FAIL`. Furthermore, for requests targeting physical page tokens (`options & (1ull << 21)`), `queue_enqueue_request` computed page token count using `destination_size` (64 KiB), capturing only 1 token and dropping subsequent page tokens for multi-page requests. ## Change 1. In `src/startup_stubs/xcrdapi.cpp`: - Read `uncompressed_size` from `request + 0x38` (matching Microsoft DirectStorage specification, where `UncompressedSize` can exceed `Destination.Size` for non-memory destinations). - In `queue_enqueue_request`: compute `size = (uncompressed_size > destination_size) ? uncompressed_size : destination_size` so all physical page tokens are retained in `entry.tokens`. - In `execute_request`: size decompression buffer to `std::max(destination_size, uncompressed_size)`. If decompression requires more space (e.g. if `uncompressed_size` is unset), expand dynamically up to 512 KiB. - Bound destination writes to `destination_size`, ensuring buffer safety. 2. In `tests/dstorage_rfc1950_check.cpp`: - Added test scenarios `large_128k` (128 KiB) and `large_256k` (256 KiB) testing full RFC 1950 stream decompression through the DirectStorage file queue with exact byte verification. - Added negative control `overflow_64k`: a 128 KiB stream submitted to a 64 KiB destination buffer. Verifies that decompression rejects the oversized payload with `0x8007000d` (`ERROR_INVALID_DATA`), preserves all sentinel bytes without buffer overrun, and reports completion status `0x8007000d`. ## Verification - Windows 11 Pro x64 (build 26100), MSVC 19.51 (VS 2026 Developer PowerShell), DirectStorage SDK 1.3.0, zlib 1.3.1. - `release` preset: `ctest --preset release --no-tests=error -R '^dstorage_rfc1950_' -V` (9/9 pass, 0.17s) `ctest --preset release --no-tests=error -R '^startup_stubs$' -V` (pass, 0.09s) - `dev` preset: `ctest --preset dev --no-tests=error -R '^dstorage_rfc1950_' -V` (9/9 pass, 0.18s) `ctest --preset dev --no-tests=error -R '^startup_stubs$' -V` (pass, 0.10s) - Linters: `tests/docs_links_check.py` (16 files, 254 links) and `tests/bidi_controls_check.py` (973 files) pass with 0 errors.
Adds opt-in desktop stand-ins (xmem, D3D12 device, DirectStorage, XG
layouts, audio HAL/APU, GameInput, gaming-runtime proxy) and a debugger
launcher under tools/startup, so the startup path of an x64 console
executable can be studied one missing piece at a time. Every stand-in is
off by default; unimplemented exports trap with a named exit code.

Includes the GPU-view mirror for paired reservations, deferred
DirectStorage queues, the second user-provider interface, 3D image
support and constant-folded inline samplers in the shader translator,
and tests/startup_stub_check.py (ctest startup_stubs).

Documented in docs/startup-runtime.md, including the shortcuts that are
known to be wrong.

AI-assisted (Claude Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:45:35 +00:00
github-bot closed this pull request 2026-11-26 22:45:35 +00:00
Author
Owner

@⁠Holastor on GitHub · 2026-11-24 02:26 UTC · original

Closing for now: Issue #1144 fixes code in PR #1135 (src/startup_stubs/), which is still open and pending merge into main. Opening against main pulled in the 9,600+ lines of PR #1135. Our actual change is strictly 46 additions / 14 deletions across 4 files (detailed in #1144). I will reopen a clean PR once #1135 lands on main.

**@⁠Holastor** on GitHub · 2026-11-24 02:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1167#issuecomment-7120151534) Closing for now: Issue #1144 fixes code in PR #1135 (src/startup_stubs/), which is still open and pending merge into main. Opening against main pulled in the 9,600+ lines of PR #1135. Our actual change is strictly 46 additions / 14 deletions across 4 files (detailed in #1144). I will reopen a clean PR once #1135 lands on main.
Author
Owner

@⁠Holastor on GitHub · 2026-11-24 02:58 UTC · original

Thank you @⁠tedin7 for the review!

Good catch on queue_enqueue_request: we updated pages to be bounded strictly by destination_size ((page_offset + destination_size + 0xFFFF) / 0x10000), ensuring we never read past the caller's token array. Furthermore, per maintainer @⁠R0Y00's guidance, destination_capacity and decode_length are now strictly tracked as separate values in execute_request, and multi-page grants as well as negative controls (verifying destination memory remains untouched on exceeded capacity or missing grant) have been integrated and verified in ests/startup_stub_consumer.cpp and ests/startup_stub_check.py.

Full details and test logs have been posted on Issue #1144 (#1144). We will reopen a clean, standalone PR once PR #1135 merges.

**@⁠Holastor** on GitHub · 2026-11-24 02:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1167#issuecomment-7120656871) Thank you @⁠tedin7 for the review! Good catch on queue_enqueue_request: we updated pages to be bounded strictly by destination_size ((page_offset + destination_size + 0xFFFF) / 0x10000), ensuring we never read past the caller's token array. Furthermore, per maintainer @⁠R0Y00's guidance, destination_capacity and decode_length are now strictly tracked as separate values in execute_request, and multi-page grants as well as negative controls (verifying destination memory remains untouched on exceeded capacity or missing grant) have been integrated and verified in ests/startup_stub_consumer.cpp and ests/startup_stub_check.py. Full details and test logs have been posted on Issue #1144 (https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/1144). We will reopen a clean, standalone PR once PR #1135 merges.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 02:27 UTC · original · reviewed

Reviewed commit 1089f77cd49d45f458dc6de4801189e7a04b3de1 on Linux.

Code notes:

  • src/startup_stubs/xcrdapi.cpp: execute_request sizes the inflate buffer from max(uncompressed_size, destination_size) (with a 512 KiB fallback) and still clamps destination writes to destination_size. One minor question in queue_enqueue_request: pages for page_destination is also computed from max(uncompressed_size, destination_size); if a title's token array only covers destination_size, x2w_local::readable(title, pages * sizeof(ULONG_PTR)) could reject a request whose uncompressed_size crosses into an extra 64 KiB page.
  • tests/dstorage_rfc1950_check.cpp and CMakeLists.txt: cleanly add large_128k, large_256k, and overflow_64k scenarios.

Linux checks passed: python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, python3 tests/gpu_report_format_check.py, python3 tests/xgameruntime_table_check.py, python3 tests/hardware_reports_check.py.
Windows MSVC build, DirectStorage SDK tests, and runtime behavior rely on CI (currently pending).

**@⁠tedin7** on GitHub · 2026-11-24 02:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1167#pullrequestreview-6032752880) · **reviewed** Reviewed commit `1089f77cd49d45f458dc6de4801189e7a04b3de1` on Linux. Code notes: - `src/startup_stubs/xcrdapi.cpp`: `execute_request` sizes the inflate buffer from `max(uncompressed_size, destination_size)` (with a 512 KiB fallback) and still clamps destination writes to `destination_size`. One minor question in `queue_enqueue_request`: `pages` for `page_destination` is also computed from `max(uncompressed_size, destination_size)`; if a title's token array only covers `destination_size`, `x2w_local::readable(title, pages * sizeof(ULONG_PTR))` could reject a request whose `uncompressed_size` crosses into an extra 64 KiB page. - `tests/dstorage_rfc1950_check.cpp` and `CMakeLists.txt`: cleanly add `large_128k`, `large_256k`, and `overflow_64k` scenarios. Linux checks passed: `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py`, `python3 tests/gpu_report_format_check.py`, `python3 tests/xgameruntime_table_check.py`, `python3 tests/hardware_reports_check.py`. Windows MSVC build, DirectStorage SDK tests, and runtime behavior rely on CI (currently pending).

Pull request closed

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