startup: track decode length and destination capacity separately, support chunked zlib streams #1207

Merged
Holastor merged 7 commits from upstream-pr/1214 into main 2026-11-24 05:20:40 +00:00
Holastor commented 2026-11-24 03:37:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T03:37:11Z.


Change

Resolves DirectStorage zlib request failures and chunked streaming read asserts in the startup stand-in (src/startup_stubs/xcrdapi.cpp):

  1. Separation of Decode Length and Destination Capacity (Fixes #1144):

    • destination_capacity is fixed to the caller-supplied destination_size.
    • decode_length tracks actual decompressed bytes (produced) from inflate_zlib.
    • In queue_enqueue_request, page token bounds are computed strictly from destination_size ((page_offset + destination_size + 0xFFFF) / 0x10000), preventing out-of-bounds reads into the caller's token array.
    • If decode_length > destination_capacity, or if page grants are missing / insufficient (needed_pages > granted_pages or any required token is 0), the request fails with E_FAIL (0x80004005), and the destination memory is left completely unchanged.
  2. Chunked Streaming Reads (Fixes #1136):

    • DirectStorage streaming reads an n \times D stream in n piece requests targeting 64 KiB destinations: piece 0 starts at file offset B with a zlib header, while pieces k \ge 1 are stepped by destination size (B + k \times D) without headers.
    • Added thread-safe LRU StreamCache (up to 16 entries) indexed by (source, base_offset, compressed_size).
    • has_following_chunk inspects the queue's submitted and waiting deques for matching downstream pieces. When piece 0 expands beyond its destination capacity and following chunks are queued, the decompressed stream is cached and slice 0 ([0, D)) is served to piece 0.
    • For pieces k \ge 1, slices [k \times D, (k+1) \times D) are served directly from StreamCache.
    • Single standalone requests with an intentionally short destination continue to be rejected as exceeded destination capacity without modifying memory.
  3. Source-Built Regression Fixtures (tests/startup_stub_consumer.cpp):

    • Multi-page grants: 128 KiB stream decompressed across 2 physical pages (64 KiB each), verified byte-for-byte.
    • Short destination negative control: 128 KiB stream into 64 KiB page destination prefilled with 0xAA; verifies E_FAIL and 100% unchanged memory (0xAA).
    • Missing grant token negative control: 128 KiB stream with tokens[1] = 0; verifies E_FAIL and 100% unchanged memory (0xAA).
    • Linear short destination negative control: 128 KiB stream into 64 KiB buffer prefilled with 0xAA; verifies E_FAIL and buffer untouched.
    • Chunked streaming read: 256 KiB stream (4 \times 64\text{ KiB}) enqueued as 4 separate requests stepped by k \times D; all complete with S_OK and match the original stream byte-for-byte.
    • Chunked invalid offset negative control: piece with out-of-bounds offset (500\text{ KiB} > 128\text{ KiB}) fails with E_FAIL leaving prefilled buffer (0xEE) untouched.

Verification

Commit 738bfc48 on top of main c02af631. Built on Windows 11 Pro x64 (build 26100), MSVC 19.51 (VS 2026 Developer PowerShell), Ninja.

Release Preset:

cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi
ctest --preset release --no-tests=error -R '^startup_stubs$' -V
test 191
    Start 191: startup_stubs

191: load acphal.dll: 9/9 exports
191: load chad.dll: 5/5 exports
191: load xapu.dll: 5/5 exports
191: load xcrdapi.dll: 1/1 exports
191: load xg_xs.dll: 2/2 exports
191: load gameinput.dll: 1/1 exports
191: load xmem.dll: 7/7 exports
191: load d3d12_xs.dll: 1/1 exports
191: chad: exit=0xe2570200 ok
191: xg_xs: exit=0xe2570501 ok
191: none control: exit=0 ok
191: physical control: exit=0 ok
191: dstorage control: exit=0 ok
191: PASS
1/1 Test #191: startup_stubs ....................   Passed    0.19 sec

Dev Preset:

cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi
ctest --preset dev --no-tests=error -R '^startup_stubs$' -V
1/1 Test #191: startup_stubs ....................   Passed    0.55 sec

Linters:
python -B tests/docs_links_check.py (16 files, 269 links) and python -B tests/bidi_controls_check.py (1005 files) pass with 0 errors.


Checklist

  • This pull request covers one reviewable behavior: DirectStorage bounds checking and chunked stream decompression in the startup stand-in.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case: short destination, missing grant token, linear short buffer, and out-of-bounds chunk offset, confirming destination memory remains unchanged in every failure.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6574046038 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T03:37:11Z. --- ## Change Resolves DirectStorage zlib request failures and chunked streaming read asserts in the startup stand-in (`src/startup_stubs/xcrdapi.cpp`): 1. **Separation of Decode Length and Destination Capacity (Fixes #1144):** - `destination_capacity` is fixed to the caller-supplied `destination_size`. - `decode_length` tracks actual decompressed bytes (`produced`) from `inflate_zlib`. - In `queue_enqueue_request`, page token bounds are computed strictly from `destination_size` (`(page_offset + destination_size + 0xFFFF) / 0x10000`), preventing out-of-bounds reads into the caller's token array. - If `decode_length > destination_capacity`, or if page grants are missing / insufficient (`needed_pages > granted_pages` or any required token is 0), the request fails with `E_FAIL` (`0x80004005`), and the destination memory is left **completely unchanged**. 2. **Chunked Streaming Reads (Fixes #1136):** - DirectStorage streaming reads an $n \times D$ stream in $n$ piece requests targeting 64 KiB destinations: piece 0 starts at file offset $B$ with a zlib header, while pieces $k \ge 1$ are stepped by destination size ($B + k \times D$) without headers. - Added thread-safe LRU `StreamCache` (up to 16 entries) indexed by `(source, base_offset, compressed_size)`. - `has_following_chunk` inspects the queue's `submitted` and `waiting` deques for matching downstream pieces. When piece 0 expands beyond its destination capacity and following chunks are queued, the decompressed stream is cached and slice 0 ($[0, D)$) is served to piece 0. - For pieces $k \ge 1$, slices $[k \times D, (k+1) \times D)$ are served directly from `StreamCache`. - Single standalone requests with an intentionally short destination continue to be rejected as exceeded destination capacity without modifying memory. 3. **Source-Built Regression Fixtures (`tests/startup_stub_consumer.cpp`):** - Multi-page grants: 128 KiB stream decompressed across 2 physical pages (64 KiB each), verified byte-for-byte. - Short destination negative control: 128 KiB stream into 64 KiB page destination prefilled with `0xAA`; verifies `E_FAIL` and 100% unchanged memory (`0xAA`). - Missing grant token negative control: 128 KiB stream with `tokens[1] = 0`; verifies `E_FAIL` and 100% unchanged memory (`0xAA`). - Linear short destination negative control: 128 KiB stream into 64 KiB buffer prefilled with `0xAA`; verifies `E_FAIL` and buffer untouched. - Chunked streaming read: 256 KiB stream ($4 \times 64\text{ KiB}$) enqueued as 4 separate requests stepped by $k \times D$; all complete with `S_OK` and match the original stream byte-for-byte. - Chunked invalid offset negative control: piece with out-of-bounds offset ($500\text{ KiB} > 128\text{ KiB}$) fails with `E_FAIL` leaving prefilled buffer (`0xEE`) untouched. --- ## Verification Commit 738bfc48 on top of `main` c02af631. Built on Windows 11 Pro x64 (build 26100), MSVC 19.51 (VS 2026 Developer PowerShell), Ninja. **Release Preset:** ```powershell cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi ctest --preset release --no-tests=error -R '^startup_stubs$' -V ``` ```text test 191 Start 191: startup_stubs 191: load acphal.dll: 9/9 exports 191: load chad.dll: 5/5 exports 191: load xapu.dll: 5/5 exports 191: load xcrdapi.dll: 1/1 exports 191: load xg_xs.dll: 2/2 exports 191: load gameinput.dll: 1/1 exports 191: load xmem.dll: 7/7 exports 191: load d3d12_xs.dll: 1/1 exports 191: chad: exit=0xe2570200 ok 191: xg_xs: exit=0xe2570501 ok 191: none control: exit=0 ok 191: physical control: exit=0 ok 191: dstorage control: exit=0 ok 191: PASS 1/1 Test #191: startup_stubs .................... Passed 0.19 sec ``` **Dev Preset:** ```powershell cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi ctest --preset dev --no-tests=error -R '^startup_stubs$' -V ``` ```text 1/1 Test #191: startup_stubs .................... Passed 0.55 sec ``` **Linters:** `python -B tests/docs_links_check.py` (16 files, 269 links) and `python -B tests/bidi_controls_check.py` (1005 files) pass with 0 errors. --- ## Checklist - [x] This pull request covers one reviewable behavior: DirectStorage bounds checking and chunked stream decompression in the startup stand-in. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case: short destination, missing grant token, linear short buffer, and out-of-bounds chunk offset, confirming destination memory remains unchanged in every failure. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:46:58 +00:00
tedin7 commented 2026-11-24 06:46:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:41:03Z.

Review: COMMENTED


Technical review on Linux (Windows build/tests were not executed locally).

Checks run (Linux, commit 738bfc48)

  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (16 Markdown files, 269 links).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (1005 files).

Findings

  1. Unsigned overflow in StreamCache::get_slice (src/startup_stubs/xcrdapi.cpp):
    const u64 delta = offset - it->base_offset;
    if (delta + need_bytes <= it->data.size()) {
    
    When offset - it->base_offset is near UINT64_MAX, delta + need_bytes can wrap around past 0 and pass the <= it->data.size() check, causing it->data.begin() + delta to index out of bounds. Checking delta <= it->data.size() && need_bytes <= it->data.size() - delta avoids the overflow.
  2. Observation on has_following_chunk (src/startup_stubs/xcrdapi.cpp):
    has_following_chunk inspects work.submitted and work.waiting at the moment piece 0 executes, which works when all chunks are enqueued before Submit() (as in dstorage_checks), though separate Submit() calls per chunk would not see later chunks yet.

Separation of decode_length vs. destination_capacity, page grant checks (needed_pages <= granted_pages and non-null tokens[i]), failure accounting (failed), and the dstorage positive/negative controls in tests/startup_stub_consumer.cpp are otherwise clean and title-neutral.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033311191 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#pullrequestreview-6033311191). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:41:03Z. **Review:** COMMENTED --- Technical review on Linux (Windows build/tests were **not** executed locally). ### Checks run (Linux, commit `738bfc48`) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: passed (`16` Markdown files, `269` links). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: passed (`1005` files). ### Findings 1. **Unsigned overflow in `StreamCache::get_slice` (`src/startup_stubs/xcrdapi.cpp`)**: ```cpp const u64 delta = offset - it->base_offset; if (delta + need_bytes <= it->data.size()) { ``` When `offset - it->base_offset` is near `UINT64_MAX`, `delta + need_bytes` can wrap around past `0` and pass the `<= it->data.size()` check, causing `it->data.begin() + delta` to index out of bounds. Checking `delta <= it->data.size() && need_bytes <= it->data.size() - delta` avoids the overflow. 2. **Observation on `has_following_chunk` (`src/startup_stubs/xcrdapi.cpp`)**: `has_following_chunk` inspects `work.submitted` and `work.waiting` at the moment piece 0 executes, which works when all chunks are enqueued before `Submit()` (as in `dstorage_checks`), though separate `Submit()` calls per chunk would not see later chunks yet. Separation of `decode_length` vs. `destination_capacity`, page grant checks (`needed_pages <= granted_pages` and non-null `tokens[i]`), failure accounting (`failed`), and the `dstorage` positive/negative controls in `tests/startup_stub_consumer.cpp` are otherwise clean and title-neutral.
tedin7 commented 2026-11-24 06:46:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:51:28Z.

Review: COMMENTED


Retest on Linux at commit 50f56203 (delta 738bfc48..50f56203; Windows build/tests were not executed locally).

Findings

  • StreamCache::get_slice & has_following_chunk wraparound (src/startup_stubs/xcrdapi.cpp): resolved. get_slice now checks delta <= it->data.size() && need_bytes <= it->data.size() - delta, and has_following_chunk checks e_offset > offset && e_offset - offset == destination_size, preventing u64 addition wraparound. (has_following_chunk still assumes chunks are enqueued before Submit(), as noted in the prior review.)
  • Negative control (tests/startup_stub_consumer.cpp): added piece 2 with near-wrapping offset 0xFFFFFFFFFFFF0000ull, verifying hr2 != 0 and dest2 remains 0xDD. (Minor comment nit: line 577 says UINT64_MAX - 0x10000 while the literal is UINT64_MAX - 0xFFFF.)

Checks run (Linux, 50f56203)

  • /root/.local/share/x2w-rev-venv/bin/python -B -m py_compile tests/startup_stub_check.py: passed.
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (16 Markdown files, 269 links).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (1005 tracked files).
  • git diff --check 738bfc48..50f56203: passed.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033388256 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#pullrequestreview-6033388256). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:51:28Z. **Review:** COMMENTED --- Retest on Linux at commit `50f56203` (delta `738bfc48..50f56203`; Windows build/tests were **not** executed locally). ### Findings - **`StreamCache::get_slice` & `has_following_chunk` wraparound (`src/startup_stubs/xcrdapi.cpp`)**: resolved. `get_slice` now checks `delta <= it->data.size() && need_bytes <= it->data.size() - delta`, and `has_following_chunk` checks `e_offset > offset && e_offset - offset == destination_size`, preventing `u64` addition wraparound. (`has_following_chunk` still assumes chunks are enqueued before `Submit()`, as noted in the prior review.) - **Negative control (`tests/startup_stub_consumer.cpp`)**: added piece 2 with near-wrapping offset `0xFFFFFFFFFFFF0000ull`, verifying `hr2 != 0` and `dest2` remains `0xDD`. (Minor comment nit: line 577 says `UINT64_MAX - 0x10000` while the literal is `UINT64_MAX - 0xFFFF`.) ### Checks run (Linux, `50f56203`) - `/root/.local/share/x2w-rev-venv/bin/python -B -m py_compile tests/startup_stub_check.py`: passed. - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: passed (`16` Markdown files, `269` links). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: passed (`1005` tracked files). - `git diff --check 738bfc48..50f56203`: passed.
R0Y00 commented 2026-11-24 06:46:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T03:58:42Z.

Review: CHANGES_REQUESTED


The capacity and wrap checks are separate from stream identity. The global cache can supply a slice to an unrelated standalone read that shares the source and compressed size, because cache lookup happens before the request is identified as a continuation. Please tie each cached slice to the identified queue and continuation requests for a live source. Keep memory requests on direct decode unless their source lifetime and identity can be proved. Add a source-built control where a standalone valid stream shares the cache-key fields and still decodes its own bytes. Also bound the failure diagnostic to the input length so a short invalid header reports a failure without reading beyond it.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033438218 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#pullrequestreview-6033438218). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T03:58:42Z. **Review:** CHANGES_REQUESTED --- The capacity and wrap checks are separate from stream identity. The global cache can supply a slice to an unrelated standalone read that shares the source and compressed size, because cache lookup happens before the request is identified as a continuation. Please tie each cached slice to the identified queue and continuation requests for a live source. Keep memory requests on direct decode unless their source lifetime and identity can be proved. Add a source-built control where a standalone valid stream shares the cache-key fields and still decodes its own bytes. Also bound the failure diagnostic to the input length so a short invalid header reports a failure without reading beyond it.
lambirou commented 2026-11-24 06:46:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T04:23:26Z.

Review: COMMENTED


Independent Release verification on main at b5cb8800 with the #1214 diff applied.

Environment: Windows 10.0.26300.10075, MSVC 19.44.35228.0, Ninja, AMD Radeon RX 9060 XT 32.0.32029.2010 and WARP.

  • ctest --preset release --no-tests=error -R '^startup_stubs$' -V: 1/1 passed. The extended startup_stubs fixture, including the DirectStorage cases, passes.
  • git diff --check: passed.
  • tests/docs_links_check.py: 16 Markdown files / 272 links, passed.
  • tests/bidi_controls_check.py: 1008 files, passed.

The PR also has a successful Windows checks run at 50f56203 (run 2965). No game files, dumps or private logs were used. From this independent run, the change is ready to merge.

AI-assisted (Codex).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033620985 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#pullrequestreview-6033620985). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-24T04:23:26Z. **Review:** COMMENTED --- Independent Release verification on `main` at `b5cb8800` with the #1214 diff applied. Environment: Windows 10.0.26300.10075, MSVC 19.44.35228.0, Ninja, AMD Radeon RX 9060 XT 32.0.32029.2010 and WARP. - `ctest --preset release --no-tests=error -R '^startup_stubs$' -V`: 1/1 passed. The extended `startup_stubs` fixture, including the DirectStorage cases, passes. - `git diff --check`: passed. - `tests/docs_links_check.py`: 16 Markdown files / 272 links, passed. - `tests/bidi_controls_check.py`: 1008 files, passed. The PR also has a successful Windows checks run at `50f56203` (run 2965). No game files, dumps or private logs were used. From this independent run, the change is ready to merge. AI-assisted (Codex).
tedin7 commented 2026-11-24 06:46:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:37:19Z.

Review: COMMENTED


Linux retest at commit d6c9a773 (delta 50f56203..d6c9a773; Windows build and startup_stubs runtime tests were not executed locally).

Delta 50f56203..d6c9a773 audit

  • src/startup_stubs/xcrdapi.cpp:
    • StreamCache moved into per-queue QueueWork::cached_streams (max_cached_streams = 16), guarded by work.mutex.
    • has_zlib_header(input, source_size) validates CMF/FLG (cmf & 0x0F == 8, cmf >> 4 <= 7, (cmf * 256 + flg) % 31 == 0). When a request presents a valid zlib header and inflate_zlib fails, decode_error = true prevents falling through to work.cached_streams, keeping damaged standalone streams distinct from continuation slices.
    • Continuation lookup is restricted to !direct_decoded && !decode_error && !memory_source && self && self->work with file_object->kind == file && file_object->handle != INVALID_HANDLE_VALUE, offset > it->base_offset, destination_size > 0 && (delta % destination_size) == 0, and overflow-safe bounds checks (delta <= it->data.size() && destination_size <= it->data.size() - delta).
    • has_following_chunk rejects e_options & 0x400000 (memory sources) and requires e_offset > offset && e_offset - offset == destination_size.
  • tests/startup_stub_consumer.cpp: chunked-stream and negative out-of-bounds/near-wrap controls updated to file-backed sources (OpenFile / CloseFile), plus new controls for standalone streams sharing compressed_size and damaged-checksum streams at a matching continuation offset (dest_bad remains 0xBB).

Checks run (Linux, commit d6c9a773)

  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (Self-test passed. Checked 1005 tracked source, script and build/CI files: no bidirectional controls.).
  • Windows build and tests/startup_stub_check.py / startup_stub_consumer.cpp: not executed on Linux (startup_stub_check.py requires Windows kernel32 and built DLLs/EXE).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033715518 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#pullrequestreview-6033715518). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:37:19Z. **Review:** COMMENTED --- Linux retest at commit `d6c9a773` (delta `50f56203..d6c9a773`; Windows build and `startup_stubs` runtime tests were **not** executed locally). ### Delta `50f56203..d6c9a773` audit - `src/startup_stubs/xcrdapi.cpp`: - `StreamCache` moved into per-queue `QueueWork::cached_streams` (`max_cached_streams = 16`), guarded by `work.mutex`. - `has_zlib_header(input, source_size)` validates CMF/FLG (`cmf & 0x0F == 8`, `cmf >> 4 <= 7`, `(cmf * 256 + flg) % 31 == 0`). When a request presents a valid zlib header and `inflate_zlib` fails, `decode_error = true` prevents falling through to `work.cached_streams`, keeping damaged standalone streams distinct from continuation slices. - Continuation lookup is restricted to `!direct_decoded && !decode_error && !memory_source && self && self->work` with `file_object->kind == file && file_object->handle != INVALID_HANDLE_VALUE`, `offset > it->base_offset`, `destination_size > 0 && (delta % destination_size) == 0`, and overflow-safe bounds checks (`delta <= it->data.size() && destination_size <= it->data.size() - delta`). - `has_following_chunk` rejects `e_options & 0x400000` (memory sources) and requires `e_offset > offset && e_offset - offset == destination_size`. - `tests/startup_stub_consumer.cpp`: chunked-stream and negative out-of-bounds/near-wrap controls updated to file-backed sources (`OpenFile` / `CloseFile`), plus new controls for standalone streams sharing `compressed_size` and damaged-checksum streams at a matching continuation offset (`dest_bad` remains `0xBB`). ### Checks run (Linux, commit `d6c9a773`) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: passed (`Self-test passed. Checked 1005 tracked source, script and build/CI files: no bidirectional controls.`). - Windows build and `tests/startup_stub_check.py` / `startup_stub_consumer.cpp`: **not executed** on Linux (`startup_stub_check.py` requires Windows `kernel32` and built DLLs/EXE).
R0Y00 commented 2026-11-24 06:46:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T05:18:54Z.

Review: APPROVED


Verified the submission ID and entry ID design and the original size, checksum, and physical-destination controls in Windows Release. For the concurrent-batch control, the first worker is held at an existing queue signal until the second Submit has returned. The gated test passed on this commit and failed with only the submission-ID check removed. The shared implementation credits the contribution from #1235.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034094390 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#pullrequestreview-6034094390). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T05:18:54Z. **Review:** APPROVED --- Verified the submission ID and entry ID design and the original size, checksum, and physical-destination controls in Windows Release. For the concurrent-batch control, the first worker is held at an existing queue signal until the second Submit has returned. The gated test passed on this commit and failed with only the submission-ID check removed. The shared implementation credits the contribution from #1235.
Holastor commented 2026-11-24 06:50:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T03:44:43Z.


Thank you @tedin7 for the careful review and catching that edge case!

Updated in commit 50f56203:

  1. Unsigned overflow fix: StreamCache::get_slice now checks delta <= it->data.size() && need_bytes <= it->data.size() - delta, mathematically preventing any addition wrap-around. Similarly, has_following_chunk now checks e_offset > offset && e_offset - offset == destination_size.
  2. Negative control: Added an explicit near-wrapping offset control (offset = 0xFFFFFFFFFFFF0000ull) to startup_stub_consumer, confirming it cleanly fails with E_FAIL and leaves destination memory untouched (
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121379567 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7121379567). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T03:44:43Z. --- Thank you @tedin7 for the careful review and catching that edge case! Updated in commit 50f56203: 1. **Unsigned overflow fix**: StreamCache::get_slice now checks delta <= it->data.size() && need_bytes <= it->data.size() - delta, mathematically preventing any addition wrap-around. Similarly, has_following_chunk now checks e_offset > offset && e_offset - offset == destination_size. 2. **Negative control**: Added an explicit near-wrapping offset control (offset = 0xFFFFFFFFFFFF0000ull) to startup_stub_consumer, confirming it cleanly fails with E_FAIL and leaves destination memory untouched (
Holastor commented 2026-11-24 06:50:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T04:16:36Z.


Thank you @R0Y00 and @tedin7 for the detailed feedback and requirements.

Addressed in commit 5ad75b5c:

  1. Queue-scoped stream caching:

    • Moved CachedStream and cached_streams into struct QueueWork. Stream caching and continuation lookups are now strictly tied to the identified queue instance (self->work), eliminating global static cache state across queues.
  2. Strict direct decode for memory requests:

    • Memory requests (options & 0x400000) stay strictly on direct decode. Chunk continuation lookups and piece 0 caching are restricted exclusively to live file sources (!memory_source && file_object && file_object->kind == file && file_object->handle != INVALID_HANDLE_VALUE).
  3. Stream identity & continuation identification:

    • Requests are checked for an RFC 1950 zlib header and direct decode is attempted first. A request is only treated as a continuation candidate if direct decode was not used / failed, and it satisfies continuation criteria (offset > it->base_offset, (offset - it->base_offset) % destination_size == 0, and valid slice bounds without addition overflow).
  4. Source-built control with shared cache-key fields:

    • Extended startup_stub_consumer under scenario dstorage:
      • Creates Stream 1 (64 KiB of 0x33) and Stream 2 (64 KiB of 0x77), both having the exact same compressed size S, in the same temporary file object at offsets 0 and 128 KiB.
      • Stream 1 is enqueued as a chunked read (piece 0 offset 0, piece 1 offset 32 KiB) into 32 KiB destinations, populating the queue's cached stream.
      • Stream 2 is enqueued at offset 128 KiB into a 64 KiB destination, sharing the exact same file object (source) and compressed size S.
      • Verifies that Stream 2 decodes its own bytes (0x77) directly and is not intercepted by Stream 1's cached entry.
      • The 4-chunk streaming read and out-of-bounds / near-wrapping negative controls have also been ported to exercise file sources.
  5. Bounded failure diagnostic:

    • In xcrdapi.cpp, diagnostic header logging reads at most source_size bytes into a zero-initialized array (unsigned h[4] = {}; for (unsigned i = 0; i < 4 && i < source_size; ++i) h[i] = input[i];), preventing any out-of-bounds reads when source_size < 4.
  6. Comment nit:

    • Corrected the comment in startup_stub_consumer.cpp to state UINT64_MAX - 0xFFFF.

Verification (commit 5ad75b5c)

Environment: Windows 11 Pro x64 (build 26100), MSVC 19.51, CMake / Ninja.

  • Dev preset:

    cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi
    ctest --preset dev -R '^startup_stubs$' -V
    
    chad: exit=0xe2570200 ok
    xg_xs: exit=0xe2570501 ok
    none control: exit=0 ok
    physical control: exit=0 ok
    dstorage control: exit=0 ok
    PASS
    1/1 Test #191: startup_stubs .................... Passed 0.23 sec
    
  • Release preset:

    cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi
    ctest --preset release -R '^startup_stubs$' -V
    
    1/1 Test #191: startup_stubs .................... Passed 0.22 sec
    
  • Checks & linters:

    • git diff --check: clean (0 errors).
    • tests/docs_links_check.py: passed (16 files, 269 links).
    • tests/bidi_controls_check.py: passed (1005 tracked files).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121870001 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7121870001). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T04:16:36Z. --- Thank you @R0Y00 and @tedin7 for the detailed feedback and requirements. Addressed in commit `5ad75b5c`: 1. **Queue-scoped stream caching**: - Moved `CachedStream` and `cached_streams` into `struct QueueWork`. Stream caching and continuation lookups are now strictly tied to the identified queue instance (`self->work`), eliminating global static cache state across queues. 2. **Strict direct decode for memory requests**: - Memory requests (`options & 0x400000`) stay strictly on direct decode. Chunk continuation lookups and piece 0 caching are restricted exclusively to live file sources (`!memory_source && file_object && file_object->kind == file && file_object->handle != INVALID_HANDLE_VALUE`). 3. **Stream identity & continuation identification**: - Requests are checked for an RFC 1950 zlib header and direct decode is attempted first. A request is only treated as a continuation candidate if direct decode was not used / failed, and it satisfies continuation criteria (`offset > it->base_offset`, `(offset - it->base_offset) % destination_size == 0`, and valid slice bounds without addition overflow). 4. **Source-built control with shared cache-key fields**: - Extended `startup_stub_consumer` under scenario `dstorage`: - Creates Stream 1 (64 KiB of `0x33`) and Stream 2 (64 KiB of `0x77`), both having the exact same compressed size $S$, in the same temporary file object at offsets 0 and 128 KiB. - Stream 1 is enqueued as a chunked read (piece 0 offset 0, piece 1 offset 32 KiB) into 32 KiB destinations, populating the queue's cached stream. - Stream 2 is enqueued at offset 128 KiB into a 64 KiB destination, sharing the exact same file object (`source`) and compressed size $S$. - Verifies that Stream 2 decodes its own bytes (`0x77`) directly and is not intercepted by Stream 1's cached entry. - The 4-chunk streaming read and out-of-bounds / near-wrapping negative controls have also been ported to exercise file sources. 5. **Bounded failure diagnostic**: - In `xcrdapi.cpp`, diagnostic header logging reads at most `source_size` bytes into a zero-initialized array (`unsigned h[4] = {}; for (unsigned i = 0; i < 4 && i < source_size; ++i) h[i] = input[i];`), preventing any out-of-bounds reads when `source_size < 4`. 6. **Comment nit**: - Corrected the comment in `startup_stub_consumer.cpp` to state `UINT64_MAX - 0xFFFF`. --- ### Verification (commit `5ad75b5c`) **Environment:** Windows 11 Pro x64 (build 26100), MSVC 19.51, CMake / Ninja. - **Dev preset:** ```text cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi ctest --preset dev -R '^startup_stubs$' -V ``` ```text chad: exit=0xe2570200 ok xg_xs: exit=0xe2570501 ok none control: exit=0 ok physical control: exit=0 ok dstorage control: exit=0 ok PASS 1/1 Test #191: startup_stubs .................... Passed 0.23 sec ``` - **Release preset:** ```text cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi ctest --preset release -R '^startup_stubs$' -V ``` ```text 1/1 Test #191: startup_stubs .................... Passed 0.22 sec ``` - **Checks & linters:** - `git diff --check`: clean (0 errors). - `tests/docs_links_check.py`: passed (16 files, 269 links). - `tests/bidi_controls_check.py`: passed (1005 tracked files).
tedin7 commented 2026-11-24 06:50:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:21:34Z.


Independent Windows retest on commit 5ad75b5c71c47826d7e9bf7dfcc27677f16d724d (pull/1214/head):

Environment

  • OS: Windows Server 2025 Build 26100
  • Compiler: MSVC 14.44.35207 (cl.exe / ml64.exe x64)
  • CPU: AMD Ryzen 5 PRO 5650U (Zen 3)
  • GPU driver: Microsoft Basic Render Driver (WARP)

Commands & Results

  1. Debug (dev preset):

    cmake --build --preset dev --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput xmem_shim d3d12_xs_shim -- -j 6
    ctest --preset dev -R "^startup_stubs$" --no-tests=error --output-on-failure -V
    

    Result: 1/1 passed (startup_stubs: 0.49 sec; load xcrdapi.dll: 1/1 exports, dstorage control: exit=0 ok, PASS).

  2. Release (/O2, release preset):

    cmake --preset release
    cmake --build --preset release --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput xmem_shim d3d12_xs_shim -- -j 6
    ctest --preset release -R "^startup_stubs$" --no-tests=error --output-on-failure -V
    

    Result: 1/1 passed (startup_stubs: 0.38 sec; load xcrdapi.dll: 1/1 exports, dstorage control: exit=0 ok, PASS).

0 failed, 0 skipped.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121945339 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7121945339). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:21:34Z. --- Independent Windows retest on commit `5ad75b5c71c47826d7e9bf7dfcc27677f16d724d` (`pull/1214/head`): **Environment** - OS: Windows Server 2025 Build 26100 - Compiler: MSVC `14.44.35207` (`cl.exe` / `ml64.exe` x64) - CPU: AMD Ryzen 5 PRO 5650U (Zen 3) - GPU driver: Microsoft Basic Render Driver (`WARP`) **Commands & Results** 1. **Debug (`dev` preset):** ```powershell cmake --build --preset dev --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput xmem_shim d3d12_xs_shim -- -j 6 ctest --preset dev -R "^startup_stubs$" --no-tests=error --output-on-failure -V ``` Result: **1/1 passed** (`startup_stubs`: `0.49 sec`; `load xcrdapi.dll: 1/1 exports`, `dstorage control: exit=0 ok`, `PASS`). 2. **Release (`/O2`, `release` preset):** ```powershell cmake --preset release cmake --build --preset release --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput xmem_shim d3d12_xs_shim -- -j 6 ctest --preset release -R "^startup_stubs$" --no-tests=error --output-on-failure -V ``` Result: **1/1 passed** (`startup_stubs`: `0.38 sec`; `load xcrdapi.dll: 1/1 exports`, `dstorage control: exit=0 ok`, `PASS`). 0 failed, 0 skipped.
R0Y00 commented 2026-11-24 06:50:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T04:22:05Z.


The queue-local cache, direct decode for memory sources and short diagnostic all address parts of the review. One case remains: a valid zlib header followed by a checksum failure can still fall through to the cache lookup and report success at a matching offset. Keep an actual decode error distinct from a proven continuation. Please add a generated case that enqueues a standalone stream with a damaged checksum at a matching offset and verifies failure and an unchanged destination.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121953119 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7121953119). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T04:22:05Z. --- The queue-local cache, direct decode for memory sources and short diagnostic all address parts of the review. One case remains: a valid zlib header followed by a checksum failure can still fall through to the cache lookup and report success at a matching offset. Keep an actual decode error distinct from a proven continuation. Please add a generated case that enqueues a standalone stream with a damaged checksum at a matching offset and verifies failure and an unchanged destination.
lambirou commented 2026-11-24 06:50:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T04:23:58Z.


Correction to my review above: I missed the existing CHANGES_REQUESTED from @R0Y00 about the global stream cache supplying a slice to an unrelated standalone read that shares the source and compressed size.

My run covers the Release build and the current source-built tests; it does not address that cache-identity design request. Please treat the “ready to merge” sentence as withdrawn. The PR still needs the cache key tied to the identified queue/continuation request, the standalone-read control, and the bounded failure diagnostic before it is ready.

AI-assisted (Codex).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121982471 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7121982471). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-24T04:23:58Z. --- Correction to my review above: I missed the existing `CHANGES_REQUESTED` from @R0Y00 about the global stream cache supplying a slice to an unrelated standalone read that shares the source and compressed size. My run covers the Release build and the current source-built tests; it does not address that cache-identity design request. Please treat the “ready to merge” sentence as withdrawn. The PR still needs the cache key tied to the identified queue/continuation request, the standalone-read control, and the bounded failure diagnostic before it is ready. AI-assisted (Codex).
R0Y00 commented 2026-11-24 06:50:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T04:27:48Z.


RTX 4060 Laptop integration update for 5ad75b5. I rebuilt XCRDAPI from the PR head and ran the same offline startup workload. The request-failure counter reached 17, down from 37 in the earlier run. The separate BCPack zero-fill counter remained 37. The diagnostic now identifies destination-capacity rejections on zlib requests targeting physical pages, including capacities below one 64 KiB page. This comparison also included graphics updates, so it does not isolate downstream rendering changes to this DLL.

Could the follow-up fixture cover the short final destination in a multi-piece stream and distinguish it from an invalid oversized decode? Keep the destination guard intact and check guard bytes and neighboring page grants. I am retaining the integration logs locally. Refs #1144.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122042178 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7122042178). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T04:27:48Z. --- RTX 4060 Laptop integration update for 5ad75b5. I rebuilt XCRDAPI from the PR head and ran the same offline startup workload. The request-failure counter reached 17, down from 37 in the earlier run. The separate BCPack zero-fill counter remained 37. The diagnostic now identifies destination-capacity rejections on zlib requests targeting physical pages, including capacities below one 64 KiB page. This comparison also included graphics updates, so it does not isolate downstream rendering changes to this DLL. Could the follow-up fixture cover the short final destination in a multi-piece stream and distinguish it from an invalid oversized decode? Keep the destination guard intact and check guard bytes and neighboring page grants. I am retaining the integration logs locally. Refs #1144.
Holastor commented 2026-11-24 06:50:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T04:30:19Z.


Thank you @R0Y00 for pointing out this subtle fall-through case, and thank you @tedin7 and @lambirou for the independent verifications on Windows Server 2025 and Windows 10.

Addressed in commit d6c9a773:

  1. Keep decode errors distinct from continuations:

    • In execute_request (src/startup_stubs/xcrdapi.cpp), when input presents a valid RFC 1950 zlib header but decompression fails (e.g. Adler-32 checksum mismatch or corrupted payload), decode_error is set to true.
    • The continuation cache check now requires !direct_decoded && !decode_error && ..., preventing an actual decode error from falling through to the cache lookup and reporting a false success at a matching offset.
  2. Source-built negative control for damaged checksum at matching offset:

    • In tests/startup_stub_consumer.cpp, added make_fixed_deflate_zlib (RFC 1951 fixed Huffman encoder) and a dedicated regression control:
      • Stream 1 (0x33) is enqueued at offset 0 with destination 64 KiB (inflating 128 KiB and populating the queue's cached stream).
      • A standalone stream (comp_bad) sharing the exact same file object and compressed size S is placed at file offset 64 KiB (the exact matching continuation offset for Stream 1).
      • Its Adler-32 checksum is deliberately corrupted (comp_bad.back() ^= 0xFF).
      • When enqueued at offset 64 KiB into a buffer prefilled with sentinel 0xBB, inflate_zlib fails the checksum check, decode_error blocks fall-through to the cache, the request fails with non-zero HRESULT (E_FAIL), and the destination buffer remains 100% untouched (0xBB).

Verification (commit d6c9a773)

Environment: Windows 11 Pro x64 (build 26100), MSVC 19.51, CMake / Ninja.

  • Dev preset:

    cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi
    ctest --preset dev -R '^startup_stubs$' -V
    
    chad: exit=0xe2570200 ok
    xg_xs: exit=0xe2570501 ok
    none control: exit=0 ok
    physical control: exit=0 ok
    dstorage control: exit=0 ok
    PASS
    1/1 Test #191: startup_stubs .................... Passed 0.25 sec
    
  • Release preset:

    cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi
    ctest --preset release -R '^startup_stubs$' -V
    
    1/1 Test #191: startup_stubs .................... Passed 0.22 sec
    
  • Checks & linters:

    • git diff --check: clean (0 errors).
    • tests/docs_links_check.py: passed (16 files, 269 links).
    • tests/bidi_controls_check.py: passed (1005 tracked files).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122080026 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7122080026). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T04:30:19Z. --- Thank you @R0Y00 for pointing out this subtle fall-through case, and thank you @tedin7 and @lambirou for the independent verifications on Windows Server 2025 and Windows 10. Addressed in commit `d6c9a773`: 1. **Keep decode errors distinct from continuations**: - In `execute_request` (`src/startup_stubs/xcrdapi.cpp`), when input presents a valid RFC 1950 zlib header but decompression fails (e.g. Adler-32 checksum mismatch or corrupted payload), `decode_error` is set to `true`. - The continuation cache check now requires `!direct_decoded && !decode_error && ...`, preventing an actual decode error from falling through to the cache lookup and reporting a false success at a matching offset. 2. **Source-built negative control for damaged checksum at matching offset**: - In `tests/startup_stub_consumer.cpp`, added `make_fixed_deflate_zlib` (RFC 1951 fixed Huffman encoder) and a dedicated regression control: - Stream 1 (`0x33`) is enqueued at offset 0 with destination 64 KiB (inflating 128 KiB and populating the queue's cached stream). - A standalone stream (`comp_bad`) sharing the exact same file object and compressed size $S$ is placed at file offset 64 KiB (the exact matching continuation offset for Stream 1). - Its Adler-32 checksum is deliberately corrupted (`comp_bad.back() ^= 0xFF`). - When enqueued at offset 64 KiB into a buffer prefilled with sentinel `0xBB`, `inflate_zlib` fails the checksum check, `decode_error` blocks fall-through to the cache, the request fails with non-zero HRESULT (`E_FAIL`), and the destination buffer remains 100% untouched (`0xBB`). --- ### Verification (commit `d6c9a773`) **Environment:** Windows 11 Pro x64 (build 26100), MSVC 19.51, CMake / Ninja. - **Dev preset:** ```text cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi ctest --preset dev -R '^startup_stubs$' -V ``` ```text chad: exit=0xe2570200 ok xg_xs: exit=0xe2570501 ok none control: exit=0 ok physical control: exit=0 ok dstorage control: exit=0 ok PASS 1/1 Test #191: startup_stubs .................... Passed 0.25 sec ``` - **Release preset:** ```text cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi ctest --preset release -R '^startup_stubs$' -V ``` ```text 1/1 Test #191: startup_stubs .................... Passed 0.22 sec ``` - **Checks & linters:** - `git diff --check`: clean (0 errors). - `tests/docs_links_check.py`: passed (16 files, 269 links). - `tests/bidi_controls_check.py`: passed (1005 tracked files).
Holastor commented 2026-11-24 06:50:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T04:36:33Z.


Thank you @R0Y00 for the integration update and diagnostic details on the 17 remaining request failures.

Addressed in commit bb35f045:

1. Step tracking vs. short destination capacities

  • Root cause: In multi-piece streams where the final piece's destination capacity is smaller than a full 64 KiB page (D < 64\text{ KiB}, e.g. 36 KiB), matching continuation offsets with delta % destination_size == 0 failed because the offset step between pieces is dictated by the initial stream chunk size (C = 64\text{ KiB}), not the trailing piece's shorter destination size (64\text{ KiB} \pmod{36\text{ KiB}} \ne 0).
  • Fix: We now record chunk_size from piece 0 in struct CachedStream (put_stream(..., destination_size, ...)). Continuation lookups step by step = it->chunk_size ? it->chunk_size : 0x10000.
  • Short destination slicing: When (delta % step) == 0 && delta < it->data.size(), the continuation extracts slice_size = destination_size < available ? destination_size : available. Requests where destination_size <= available are fulfilled cleanly without exceeding remaining uncompressed bytes.

2. Multi-piece physical page fixture with intact guard bytes & neighboring grant checks

Extended tests/startup_stub_consumer.cpp under the dstorage scenario:

  • Case A: Short final destination in a multi-piece stream (100 KiB total: 64 KiB piece 0 + 36 KiB piece 1)
    • Targets two physical 64 KiB pages (XMemAllocPhysicalPages(2) / XMemMapPhysicalPages).
    • Pre-fills Page 1 with guard byte 0xAA.
    • Piece 0 decodes 64 KiB into Page 0 (tokens[0] = pages[0]).
    • Piece 1 decodes 36 KiB into Page 1 with 1 page grant (tokens[0] = pages[1], neighboring token tokens[1] = 0).
    • Verification:
      1. Both requests succeed (hr == 0).
      2. Page 0 matches the first 64 KiB of uncompressed data.
      3. Page 1 matches the remaining 36 KiB of uncompressed data.
      4. Guard byte verification: All bytes in Page 1 from offset 36 KiB to 64 KiB remain untouched guard bytes (0xAA).
      5. Neighboring grant verification: tokens[1] is verified to remain 0 (never read or written).

3. Negative control: Invalid oversized decode

  • Case B: Oversized decode rejected while preserving destination guards
    • Targets Page 1 (pre-filled with guard byte 0x55) with a 100 KiB standalone stream, but specifies destination capacity of 36 KiB with only 1 page grant (tokens[0] = pages[1], neighboring tokens[1] = 0).
    • Verification:
      1. Request completes and fails with non-zero HRESULT (hr != 0).
      2. Guard byte verification: Entire 64 KiB of Page 1 remains completely untouched (0x55).
      3. Neighboring grant verification: tokens[1] remains 0.

4. Build & Test Verification

Verified on Windows 11 (MSVC, C++20):

cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi
ctest --preset dev -R '^startup_stubs$' -V
cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi
ctest --preset release -R '^startup_stubs$' -V
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check

All passed without diagnostics or regressions. Refs #1144, #1214.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122175266 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7122175266). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T04:36:33Z. --- Thank you @R0Y00 for the integration update and diagnostic details on the 17 remaining request failures. Addressed in commit bb35f045: ### 1. Step tracking vs. short destination capacities - **Root cause**: In multi-piece streams where the final piece's destination capacity is smaller than a full 64 KiB page ($D < 64\text{ KiB}$, e.g. 36 KiB), matching continuation offsets with `delta % destination_size == 0` failed because the offset step between pieces is dictated by the initial stream chunk size ($C = 64\text{ KiB}$), not the trailing piece's shorter destination size ($64\text{ KiB} \pmod{36\text{ KiB}} \ne 0$). - **Fix**: We now record `chunk_size` from piece 0 in `struct CachedStream` (`put_stream(..., destination_size, ...)`). Continuation lookups step by `step = it->chunk_size ? it->chunk_size : 0x10000`. - **Short destination slicing**: When `(delta % step) == 0 && delta < it->data.size()`, the continuation extracts `slice_size = destination_size < available ? destination_size : available`. Requests where `destination_size <= available` are fulfilled cleanly without exceeding remaining uncompressed bytes. ### 2. Multi-piece physical page fixture with intact guard bytes & neighboring grant checks Extended `tests/startup_stub_consumer.cpp` under the `dstorage` scenario: - **Case A: Short final destination in a multi-piece stream (100 KiB total: 64 KiB piece 0 + 36 KiB piece 1)** - Targets two physical 64 KiB pages (`XMemAllocPhysicalPages(2)` / `XMemMapPhysicalPages`). - Pre-fills Page 1 with guard byte `0xAA`. - Piece 0 decodes 64 KiB into Page 0 (`tokens[0] = pages[0]`). - Piece 1 decodes 36 KiB into Page 1 with 1 page grant (`tokens[0] = pages[1]`, neighboring token `tokens[1] = 0`). - **Verification**: 1. Both requests succeed (`hr == 0`). 2. Page 0 matches the first 64 KiB of uncompressed data. 3. Page 1 matches the remaining 36 KiB of uncompressed data. 4. **Guard byte verification**: All bytes in Page 1 from offset 36 KiB to 64 KiB remain untouched guard bytes (`0xAA`). 5. **Neighboring grant verification**: `tokens[1]` is verified to remain `0` (never read or written). ### 3. Negative control: Invalid oversized decode - **Case B: Oversized decode rejected while preserving destination guards** - Targets Page 1 (pre-filled with guard byte `0x55`) with a 100 KiB standalone stream, but specifies destination capacity of 36 KiB with only 1 page grant (`tokens[0] = pages[1]`, neighboring `tokens[1] = 0`). - **Verification**: 1. Request completes and fails with non-zero HRESULT (`hr != 0`). 2. **Guard byte verification**: Entire 64 KiB of Page 1 remains completely untouched (`0x55`). 3. **Neighboring grant verification**: `tokens[1]` remains `0`. ### 4. Build & Test Verification Verified on Windows 11 (MSVC, C++20): ```powershell cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi ctest --preset dev -R '^startup_stubs$' -V cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi ctest --preset release -R '^startup_stubs$' -V python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py git diff --check ``` All passed without diagnostics or regressions. Refs #1144, #1214.
R0Y00 commented 2026-11-24 06:50:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T04:41:11Z.


I reran startup_stubs in Windows Release on bb35f045. The damaged-Adler32 case and the short final destination now pass.

One unrelated read can still get a successful cached result. has_following_chunk establishes that the first sibling was queued, but the cache subsequently answers any aligned offset within the inflated range when file and compressed size match. After a valid two-slice submission completes, a later independent request on the same live file and queue at the same aligned offset can still receive the first stream's bytes. Please scope the cache to the actual continuation requests identified for the stream (or expire it at a boundary that guarantees the same property). Add a source-built case with a valid chunked submission followed by a separate Submit with a same-size non-zlib read at a matching offset. The separate read should fail and leave its sentinel unchanged.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122245279 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7122245279). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T04:41:11Z. --- I reran `startup_stubs` in Windows Release on `bb35f045`. The damaged-Adler32 case and the short final destination now pass. One unrelated read can still get a successful cached result. `has_following_chunk` establishes that the first sibling was queued, but the cache subsequently answers any aligned offset within the inflated range when file and compressed size match. After a valid two-slice submission completes, a later independent request on the same live file and queue at the same aligned offset can still receive the first stream's bytes. Please scope the cache to the actual continuation requests identified for the stream (or expire it at a boundary that guarantees the same property). Add a source-built case with a valid chunked submission followed by a separate Submit with a same-size non-zlib read at a matching offset. The separate read should fail and leave its sentinel unchanged.
lambirou commented 2026-11-24 06:50:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-24T04:49:01Z.


Follow-up for the remaining cache-identity case: #1235, stacked on this PR at bb35f045. The last commit 0846d914 scopes the cache to the exact queued continuation entry ids and adds the separate-Submit control with a matching offset and an unchanged sentinel. Local Windows Release startup_stubs passes; the new control fails against the previous head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122364670 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7122364670). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-24T04:49:01Z. --- Follow-up for the remaining cache-identity case: #1235, stacked on this PR at `bb35f045`. The last commit `0846d914` scopes the cache to the exact queued continuation entry ids and adds the separate-`Submit` control with a matching offset and an unchanged sentinel. Local Windows Release `startup_stubs` passes; the new control fails against the previous head.
Holastor commented 2026-11-24 06:50:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T04:49:51Z.


Thank you @R0Y00 for the thorough review and testing!

Addressed in commit 9570cec4:

1. Scoping stream cache to identified continuations & consuming on fulfillment

  • When piece 0 inflates a chunked stream, find_continuation_offsets inspects queued entries (work.submitted and work.waiting) and records the exact matching offsets into CachedStream::pending_offsets. If no continuation entries are queued, the stream is not cached.
  • Continuation lookups now require offset to match one of the stream's pending_offsets.
  • Upon fulfilling a continuation request, that offset is erased from pending_offsets.
  • Once all identified continuations for a stream have been fulfilled (pending_offsets.empty()), the cached stream is immediately erased from work.cached_streams.

2. Submission boundary expiration

  • At the worker loop boundary, when work.submitted.empty() after processing an entry (all entries of the current submission have finished executing), any remaining cached streams in work.cached_streams are cleared. This guarantees that cached streams never persist into subsequent Submit() calls.

3. Source-built control: chunked submission followed by separate non-zlib Submit

Extended tests/startup_stub_consumer.cpp under scenario dstorage:

  • Prepares a file with a valid compressed stream at offset 0 (deflated to size S) and raw non-zlib bytes (0xEE) at continuation offset 64 KiB.
  • First Submit (valid chunked stream):
    • Enqueues piece 0 (offset 0, destination 64 KiB) and piece 1 (offset 64 KiB, destination 64 KiB).
    • Submits and waits for completion: both succeed (hr == 0) and destination buffers both verify to payload 0x44.
  • Second Submit (separate Submit on same queue and live file):
    • Enqueues a read at matching offset 64 KiB, same size S, destination 64 KiB prefilled with sentinel 0x99.
    • Submits and waits for completion.
    • Verification:
      1. The read cannot match the expired/consumed cache and direct decode on the non-zlib data fails: hr != 0 (E_FAIL).
      2. Destination buffer remains completely untouched (all bytes verified equal to sentinel 0x99).

4. Build & Test Verification

Verified on Windows 11 (MSVC, C++20):

cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi
ctest --preset dev -R '^startup_stubs$' -V
cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi
ctest --preset release -R '^startup_stubs$' -V
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check

Both dev and release passed startup_stubs cleanly, and all link and bidi checks passed without errors. Refs #1144, #1214.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122376948 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7122376948). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T04:49:51Z. --- Thank you @R0Y00 for the thorough review and testing! Addressed in commit 9570cec4: ### 1. Scoping stream cache to identified continuations & consuming on fulfillment - When piece 0 inflates a chunked stream, `find_continuation_offsets` inspects queued entries (`work.submitted` and `work.waiting`) and records the exact matching offsets into `CachedStream::pending_offsets`. If no continuation entries are queued, the stream is not cached. - Continuation lookups now require `offset` to match one of the stream's `pending_offsets`. - Upon fulfilling a continuation request, that offset is erased from `pending_offsets`. - Once all identified continuations for a stream have been fulfilled (`pending_offsets.empty()`), the cached stream is immediately erased from `work.cached_streams`. ### 2. Submission boundary expiration - At the worker loop boundary, when `work.submitted.empty()` after processing an entry (all entries of the current submission have finished executing), any remaining cached streams in `work.cached_streams` are cleared. This guarantees that cached streams never persist into subsequent `Submit()` calls. ### 3. Source-built control: chunked submission followed by separate non-zlib Submit Extended `tests/startup_stub_consumer.cpp` under scenario `dstorage`: - Prepares a file with a valid compressed stream at offset 0 (deflated to size $S$) and raw non-zlib bytes (`0xEE`) at continuation offset 64 KiB. - **First Submit (valid chunked stream)**: - Enqueues piece 0 (offset 0, destination 64 KiB) and piece 1 (offset 64 KiB, destination 64 KiB). - Submits and waits for completion: both succeed (`hr == 0`) and destination buffers both verify to payload `0x44`. - **Second Submit (separate Submit on same queue and live file)**: - Enqueues a read at matching offset 64 KiB, same size $S$, destination 64 KiB prefilled with sentinel `0x99`. - Submits and waits for completion. - **Verification**: 1. The read cannot match the expired/consumed cache and direct decode on the non-zlib data fails: `hr != 0` (`E_FAIL`). 2. Destination buffer remains completely untouched (all bytes verified equal to sentinel `0x99`). ### 4. Build & Test Verification Verified on Windows 11 (MSVC, C++20): ```powershell cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi ctest --preset dev -R '^startup_stubs$' -V cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi ctest --preset release -R '^startup_stubs$' -V python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py git diff --check ``` Both `dev` and `release` passed `startup_stubs` cleanly, and all link and bidi checks passed without errors. Refs #1144, #1214.
R0Y00 commented 2026-11-24 06:50:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T04:59:39Z.


Thanks to both authors for the separate-Submit control. #1214 now tracks offsets and #1235 tracks entry IDs, so please land one shared implementation and keep both contributions credited. The entry IDs are the stronger identity, but both candidates still search the waiting deque, which already belongs to a future Submit. Also, the worker can have two submitted batches queued at once, so an empty deque is not a submission boundary.

For the source-built scope, attach the submission identity when moving waiting entries into submitted and only admit adjacent, matching chunk entries in that same batch. Please include a deterministic check with the first request already submitted and a matching non-zlib request in the next batch before the worker examines continuations. The first request with an undersized standalone destination and the unrelated second request must fail with unchanged sentinels. If real continuation requests need to cross explicit submits, please share a source-built comparison that shows how to identify those requests without matching an independent read. The existing short tail, damaged header/checksum, and physical-page tests still apply.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122524223 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7122524223). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T04:59:39Z. --- Thanks to both authors for the separate-Submit control. #1214 now tracks offsets and #1235 tracks entry IDs, so please land one shared implementation and keep both contributions credited. The entry IDs are the stronger identity, but both candidates still search the waiting deque, which already belongs to a future Submit. Also, the worker can have two submitted batches queued at once, so an empty deque is not a submission boundary. For the source-built scope, attach the submission identity when moving waiting entries into submitted and only admit adjacent, matching chunk entries in that same batch. Please include a deterministic check with the first request already submitted and a matching non-zlib request in the next batch before the worker examines continuations. The first request with an undersized standalone destination and the unrelated second request must fail with unchanged sentinels. If real continuation requests need to cross explicit submits, please share a source-built comparison that shows how to identify those requests without matching an independent read. The existing short tail, damaged header/checksum, and physical-page tests still apply.
Holastor commented 2026-11-24 06:50:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T05:11:36Z.


Thank you @R0Y00 and @lambirou!

We have integrated the entry_id design from #1235 into PR #1214 with Co-authored-by: Roland Edi <[email protected]> in commit 4f67e704, addressing the Submit() boundary feedback.

Summary of changes

  1. submission_id and monotonic id in Entry:

    • struct Entry gains u64 id = 0; (assigned monotonically in push()) and u64 submission_id = 0;.
    • In submit(), when moving entries from work.waiting to work.submitted, all entries in that batch receive a unified submission_id = ++work.next_submission_id.
  2. following_chunk_ids() strictly scoped to the current submission:

    • Scanning of work.waiting is completely removed: following_chunk_ids now scans only work.submitted.
    • The loop skips non-request entries (status_entry) and halts (break) as soon as e.submission_id != current_submission_id, or when an unrelated/non-zlib request or offset mismatch is encountered.
    • Continuation requests are identified by their unique id, stored in CachedStream::continuation_ids.
  3. Strict continuation cache lookup & lifecycle:

    • Cache lookup in execute_request() requires entry_id to be present in it->continuation_ids.
    • Upon consuming a slice, entry_id is removed from continuation_ids. When empty, the stream is immediately erased from cached_streams.
    • At the worker loop boundary, when work.submitted.empty() after processing an entry, any leftover cached streams are cleared.
  4. Deterministic two-Submit() boundary controls (tests/startup_stub_consumer.cpp):

    • Added a deterministic boundary test exercising two consecutive Submit() calls:
      • First Submit(): Sends a compressed stream targeting an undersized destination buffer (64 KiB destination for 128 KiB uncompressed stream) with no continuation request in that batch. Because no continuation is queued in the batch, following_chunk_ids returns empty, the stream is not cached, and the request fails cleanly with destination memory untouched (0xA5).
      • Second Submit(): Immediately enqueued on the same queue and live file handle at the continuation offset (64 KiB), requesting zlib decompression on non-zlib file bytes. Because it belongs to a different submission and cannot match any cached stream, it fails cleanly with non-zero HRESULT and its destination memory remains untouched (0xB6).
    • Retained the sequential separate-Submit control testing completed multi-piece streams followed by independent reads.
  5. Documentation:

    • Documented stream-cache identity in docs/startup-runtime.md.

Verification (commit 4f67e704)

Environment: Windows 11 Pro x64 (build 26100), MSVC 19.51, CMake / Ninja.

  • Dev preset:

    cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi
    ctest --preset dev -R '^(startup_stubs|dstorage_rfc1950_)' -V
    
    1/7 Test   #1: dstorage_rfc1950_success ......... Passed 0.02 sec
    2/7 Test   #2: dstorage_rfc1950_truncated ....... Passed 0.02 sec
    3/7 Test   #3: dstorage_rfc1950_checksum ........ Passed 0.02 sec
    4/7 Test   #4: dstorage_rfc1950_trailing ........ Passed 0.02 sec
    5/7 Test   #5: dstorage_rfc1950_oversize ........ Passed 0.02 sec
    6/7 Test   #6: dstorage_rfc1950_undersize ....... Passed 0.02 sec
    7/7 Test #191: startup_stubs .................... Passed 0.63 sec
    100% tests passed, 0 tests failed out of 7
    
  • Release preset:

    cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi
    ctest --preset release -R '^(startup_stubs|dstorage_rfc1950_)' -V
    
    100% tests passed, 0 tests failed out of 7
    
  • Checks & linters:

    • git diff --check: clean (0 errors).
    • tests/docs_links_check.py: passed (16 files, 269 links).
    • tests/bidi_controls_check.py: passed (1005 files).

Refs #1144, #1214, #1235.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122712140 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1214#issuecomment-7122712140). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-24T05:11:36Z. --- Thank you @R0Y00 and @lambirou! We have integrated the `entry_id` design from #1235 into PR #1214 with `Co-authored-by: Roland Edi <[email protected]>` in commit 4f67e704, addressing the `Submit()` boundary feedback. ### Summary of changes 1. **`submission_id` and monotonic `id` in `Entry`**: - `struct Entry` gains `u64 id = 0;` (assigned monotonically in `push()`) and `u64 submission_id = 0;`. - In `submit()`, when moving entries from `work.waiting` to `work.submitted`, all entries in that batch receive a unified `submission_id = ++work.next_submission_id`. 2. **`following_chunk_ids()` strictly scoped to the current submission**: - Scanning of `work.waiting` is completely removed: `following_chunk_ids` now scans only `work.submitted`. - The loop skips non-request entries (`status_entry`) and halts (`break`) as soon as `e.submission_id != current_submission_id`, or when an unrelated/non-zlib request or offset mismatch is encountered. - Continuation requests are identified by their unique `id`, stored in `CachedStream::continuation_ids`. 3. **Strict continuation cache lookup & lifecycle**: - Cache lookup in `execute_request()` requires `entry_id` to be present in `it->continuation_ids`. - Upon consuming a slice, `entry_id` is removed from `continuation_ids`. When empty, the stream is immediately erased from `cached_streams`. - At the worker loop boundary, when `work.submitted.empty()` after processing an entry, any leftover cached streams are cleared. 4. **Deterministic two-`Submit()` boundary controls (`tests/startup_stub_consumer.cpp`)**: - Added a deterministic boundary test exercising two consecutive `Submit()` calls: - **First `Submit()`**: Sends a compressed stream targeting an undersized destination buffer (64 KiB destination for 128 KiB uncompressed stream) with **no** continuation request in that batch. Because no continuation is queued in the batch, `following_chunk_ids` returns empty, the stream is not cached, and the request fails cleanly with destination memory untouched (`0xA5`). - **Second `Submit()`**: Immediately enqueued on the same queue and live file handle at the continuation offset (64 KiB), requesting zlib decompression on non-zlib file bytes. Because it belongs to a different submission and cannot match any cached stream, it fails cleanly with non-zero HRESULT and its destination memory remains untouched (`0xB6`). - Retained the sequential separate-`Submit` control testing completed multi-piece streams followed by independent reads. 5. **Documentation**: - Documented stream-cache identity in `docs/startup-runtime.md`. --- ### Verification (commit 4f67e704) **Environment:** Windows 11 Pro x64 (build 26100), MSVC 19.51, CMake / Ninja. - **Dev preset:** ```text cmake --build --preset dev --target startup_stub_consumer startup_stub_xcrdapi ctest --preset dev -R '^(startup_stubs|dstorage_rfc1950_)' -V ``` ```text 1/7 Test #1: dstorage_rfc1950_success ......... Passed 0.02 sec 2/7 Test #2: dstorage_rfc1950_truncated ....... Passed 0.02 sec 3/7 Test #3: dstorage_rfc1950_checksum ........ Passed 0.02 sec 4/7 Test #4: dstorage_rfc1950_trailing ........ Passed 0.02 sec 5/7 Test #5: dstorage_rfc1950_oversize ........ Passed 0.02 sec 6/7 Test #6: dstorage_rfc1950_undersize ....... Passed 0.02 sec 7/7 Test #191: startup_stubs .................... Passed 0.63 sec 100% tests passed, 0 tests failed out of 7 ``` - **Release preset:** ```text cmake --build --preset release --target startup_stub_consumer startup_stub_xcrdapi ctest --preset release -R '^(startup_stubs|dstorage_rfc1950_)' -V ``` ```text 100% tests passed, 0 tests failed out of 7 ``` - **Checks & linters:** - `git diff --check`: clean (0 errors). - `tests/docs_links_check.py`: passed (16 files, 269 links). - `tests/bidi_controls_check.py`: passed (1005 files). Refs #1144, #1214, #1235.
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!1207
No description provided.