startup: support DirectStorage zlib requests exceeding destination size #1167
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!1167
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1167/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Holastor on GitHub · 2026-11-24 02:17 UTC · original
Holastor:fix/dstorage-zlib-64k→main· +9953 −1 · 39 files · 5 commits · closed without mergingRefs #1144.
Problem
In
src/startup_stubs/xcrdapi.cpp, zlib decompression requests failed when an archive stream uncompressed to more than 64 KiB. The standalone decompressorx2w_inflate::inflate_zliboperates in a single pass into a fixed linear buffer. Because the runtime sized the output buffer strictly todestination_sizeread fromrequest + 0x18(which is0x10000= 64 KiB for a single tile/page target), any stream exceeding 64 KiB ran out of buffer space, returningfalseand causingoutcome = "zlib failed"withE_FAIL.Furthermore, for requests targeting physical page tokens (
options & (1ull << 21)),queue_enqueue_requestcomputed page token count usingdestination_size(64 KiB), capturing only 1 token and dropping subsequent page tokens for multi-page requests.Change
src/startup_stubs/xcrdapi.cpp:uncompressed_sizefromrequest + 0x38(matching Microsoft DirectStorage specification, whereUncompressedSizecan exceedDestination.Sizefor non-memory destinations).queue_enqueue_request: computesize = (uncompressed_size > destination_size) ? uncompressed_size : destination_sizeso all physical page tokens are retained inentry.tokens.execute_request: size decompression buffer tostd::max(destination_size, uncompressed_size). If decompression requires more space (e.g. ifuncompressed_sizeis unset), expand dynamically up to 512 KiB.destination_size, ensuring buffer safety.tests/dstorage_rfc1950_check.cpp:large_128k(128 KiB) andlarge_256k(256 KiB) testing full RFC 1950 stream decompression through the DirectStorage file queue with exact byte verification.overflow_64k: a 128 KiB stream submitted to a 64 KiB destination buffer. Verifies that decompression rejects the oversized payload with0x8007000d(ERROR_INVALID_DATA), preserves all sentinel bytes without buffer overrun, and reports completion status0x8007000d.Verification
releasepreset: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)devpreset: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)tests/docs_links_check.py(16 files, 254 links) andtests/bidi_controls_check.py(973 files) pass with 0 errors.@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: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.
@tedin7 on GitHub · 2026-11-24 02:27 UTC · original · reviewed
Reviewed commit
1089f77cd49d45f458dc6de4801189e7a04b3de1on Linux.Code notes:
src/startup_stubs/xcrdapi.cpp:execute_requestsizes the inflate buffer frommax(uncompressed_size, destination_size)(with a 512 KiB fallback) and still clamps destination writes todestination_size. One minor question inqueue_enqueue_request:pagesforpage_destinationis also computed frommax(uncompressed_size, destination_size); if a title's token array only coversdestination_size,x2w_local::readable(title, pages * sizeof(ULONG_PTR))could reject a request whoseuncompressed_sizecrosses into an extra 64 KiB page.tests/dstorage_rfc1950_check.cppandCMakeLists.txt: cleanly addlarge_128k,large_256k, andoverflow_64kscenarios.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