runtime: check the RFC 1950 codec's refusals #1726

Merged
Asimmimx merged 1 commit from upstream-pr/1733 into main 2026-11-24 19:52:06 +00:00
Asimmimx commented 2026-11-24 17:56:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:56:38Z.


Refs #1149.

Change

src/dstorage_rfc1950.h declares the CPU side of the optional DirectStorage RFC 1950 fixture (src/dstorage_rfc1950.cpp):

  • decode handles one DSTORAGE_CUSTOM_DECOMPRESSION_REQUEST with zlib. Before zlib runs, it refuses any format other than DSTORAGE_CUSTOM_COMPRESSION_0 and any non-zero flag with E_NOTIMPL. It refuses a null or empty source or destination, or a size above ULONG_MAX, with E_INVALIDARG.
  • complete_one dequeues one job, decodes it and publishes the result under the request's ID. It returns E_POINTER for a null queue and S_FALSE for an empty one. Until a job is dequeued, decoded reads {E_PENDING, 0, 0}.

One test reaches it: the six dstorage_rfc1950_* scenarios of tests/dstorage_rfc1950_check.cpp (success, truncated, checksum, trailing, oversize, undersize). They are registered only when DSTORAGE_SDK_ROOT is set, so CI does not build them. Each scenario sends one well-formed custom-format-zero request through a real file queue, so no refusal path ran. 12 of 18 single-point mutants left all six passing (table below).

New refusals scenario. It calls decode directly with hand-built requests, each starting from a valid 116-byte stream and a 768-byte guarded destination:

Case Expected What it pins
baseline S_OK, 116 consumed, 768 produced, bytes match the request built by hand is valid, and consumed and produced are not swapped
format_custom_1: DSTORAGE_CUSTOM_COMPRESSION_0 + 1 E_NOTIMPL only custom format zero is RFC 1950. A < CUSTOM_0 test would accept it
format_gdeflate E_NOTIMPL built-in formats are refused
flag_dest_in_upload_heap E_NOTIMPL the flag gate
null_src, null_dst E_INVALIDARG the null-buffer checks (null_dst without its check writes through a null pointer)
zero_src, zero_dst E_INVALIDARG the empty-size checks, instead of the 0x8007000d that zlib's failure would give
src_over_ulong_max, dst_over_ulong_max: size + 2^32 E_INVALIDARG the 32-bit bounds. The low 32 bits still hold the true size, so a truncating codec would decode the whole stream
null_queue: complete_one(nullptr, decoded) with a stale decoded E_POINTER, decoded = E_PENDING, zero counts the null-queue check and the reset

Each refusal must also report zero bytes consumed and produced and leave the destination and its guards unchanged. The scenario prints one line per case and every failing case as FAIL: refusals <case>: .... The six queue scenarios now also check that their final empty dequeue leaves decoded at E_PENDING with zero counts. No existing check was changed.

Negative control: dstorage_rfc1950_refusals_truncation_control builds the same check against a build-tree copy of dstorage_rfc1950.cpp without request.SrcSize > ULONG_MAX || . CMake stops with FATAL_ERROR if that text is gone and re-runs when the source file changes (CMAKE_CONFIGURE_DEPENDS). The test uses PASS_REGULAR_EXPRESSION "FAIL: refusals src_over_ulong_max: status 0x8007000d" instead of WILL_FAIL, so it passes only when the check reports this specific defect. A crash does not pass it. When run directly, the control prints FAIL: refusals src_over_ulong_max: status 0x8007000d consumed=116 produced=768, expected 0x80070057, passes the other ten cases and exits 1.

The change touches tests/dstorage_rfc1950_check.cpp (one new function, a main branch and one check after the last dequeue) and the DSTORAGE_SDK_ROOT block of CMakeLists.txt (refusals added to the scenario list, plus the control). It also adds a paragraph to "Windows file-to-memory RFC 1950 requests" in docs/experiments.md. src/dstorage_rfc1950.* is unchanged.

Verification

Commit eb913fc7 on cb6f71d4 (main), dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260. DirectStorage 1.3.0 NuGet package extracted under out/dstorage-sdk. zlib 1.3.1 (zlib-1.3.1.tar.gz, SHA-256 9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23) was built as a Release zlibstatic with /MD, and its library and headers were copied under out/zlib-install. No GPU is involved; the queue uses a memory destination.

cmake --preset dev "-DDSTORAGE_SDK_ROOT=$PWD/out/dstorage-sdk" "-DZLIB_ROOT=$PWD/out/zlib-install" "-DZLIB_LIBRARY_RELEASE=$PWD/out/zlib-install/lib/zlibstatic.lib"
cmake --build --preset dev --target dstorage_rfc1950_check dstorage_rfc1950_truncation_control
ctest --preset dev --no-tests=error -R '^dstorage_rfc1950_' --repeat until-fail:10
#   8/8 passed, 10 repetitions each

tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed.

Mutation probe

I applied each mutation to src/dstorage_rfc1950.cpp alone, rebuilt dstorage_rfc1950_check and ran the scenarios, then reverted. "Existing" is the six queue scenarios on the unchanged test file and CMakeLists.txt. "With the new cases" adds refusals and the empty-dequeue check. For that run I took out the CMAKE_CONFIGURE_DEPENDS line, so the control's configure guard would not stop the SrcSize mutant. None of this is committed.

Mutant Existing six With the new cases
format test dropped survived killed (format_custom_1, format_gdeflate)
format != becomes < survived killed (format_custom_1)
Flags test dropped survived killed (flag_dest_in_upload_heap)
E_NOTIMPL becomes E_INVALIDARG survived killed
!SrcBuffer dropped survived killed (null_src: 0x8007000d)
!DstBuffer dropped survived killed (null write, crash)
!SrcSize dropped survived killed (zero_src)
!DstSize dropped survived killed (zero_dst)
SrcSize > ULONG_MAX dropped (the control) survived killed (src_over_ulong_max)
size refusal becomes E_NOTIMPL survived killed
!queue dropped survived killed (null call, crash)
decoded not reset survived killed (all seven scenarios)
used != SrcSize dropped killed (trailing) killed
written != DstSize dropped killed (oversize) killed
result published under Id + 1 killed (timeout or crash) killed
empty queue returns S_OK killed killed
S_OK published for every request killed killed
consumed and produced swapped killed (success) killed

Not pinned or not run

  • The DstSize > ULONG_MAX mutant was not run. Without the bound, decode allocates DstSize bytes (4 GiB here) before zlib runs, and the Debug heap fills that block. By reading the code, it would return E_OUTOFMEMORY or 0x8007000d instead of E_INVALIDARG, so dst_over_ulong_max would kill it, but I did not measure that.
  • The Z_MEM_ERROR to E_OUTOFMEMORY mapping and the failed allocation path. Neither is reachable without an allocation failure.
  • complete_one passing a failed GetRequests through. The DirectStorage queue gives no way to make that call fail.
  • flag_dest_in_upload_heap pins the current refusal of upload-heap destinations. If the codec later accepts them, that case should change with 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.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588105639 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1733). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:56:38Z. --- Refs #1149. ## Change `src/dstorage_rfc1950.h` declares the CPU side of the optional DirectStorage RFC 1950 fixture (`src/dstorage_rfc1950.cpp`): - `decode` handles one `DSTORAGE_CUSTOM_DECOMPRESSION_REQUEST` with zlib. Before zlib runs, it refuses any format other than `DSTORAGE_CUSTOM_COMPRESSION_0` and any non-zero flag with `E_NOTIMPL`. It refuses a null or empty source or destination, or a size above `ULONG_MAX`, with `E_INVALIDARG`. - `complete_one` dequeues one job, decodes it and publishes the result under the request's ID. It returns `E_POINTER` for a null queue and `S_FALSE` for an empty one. Until a job is dequeued, `decoded` reads `{E_PENDING, 0, 0}`. One test reaches it: the six `dstorage_rfc1950_*` scenarios of `tests/dstorage_rfc1950_check.cpp` (`success`, `truncated`, `checksum`, `trailing`, `oversize`, `undersize`). They are registered only when `DSTORAGE_SDK_ROOT` is set, so CI does not build them. Each scenario sends one well-formed custom-format-zero request through a real file queue, so no refusal path ran. 12 of 18 single-point mutants left all six passing (table below). New `refusals` scenario. It calls `decode` directly with hand-built requests, each starting from a valid 116-byte stream and a 768-byte guarded destination: | Case | Expected | What it pins | |---|---|---| | `baseline` | `S_OK`, 116 consumed, 768 produced, bytes match | the request built by hand is valid, and consumed and produced are not swapped | | `format_custom_1`: `DSTORAGE_CUSTOM_COMPRESSION_0 + 1` | `E_NOTIMPL` | only custom format zero is RFC 1950. A `< CUSTOM_0` test would accept it | | `format_gdeflate` | `E_NOTIMPL` | built-in formats are refused | | `flag_dest_in_upload_heap` | `E_NOTIMPL` | the flag gate | | `null_src`, `null_dst` | `E_INVALIDARG` | the null-buffer checks (`null_dst` without its check writes through a null pointer) | | `zero_src`, `zero_dst` | `E_INVALIDARG` | the empty-size checks, instead of the `0x8007000d` that zlib's failure would give | | `src_over_ulong_max`, `dst_over_ulong_max`: size + 2^32 | `E_INVALIDARG` | the 32-bit bounds. The low 32 bits still hold the true size, so a truncating codec would decode the whole stream | | `null_queue`: `complete_one(nullptr, decoded)` with a stale `decoded` | `E_POINTER`, `decoded` = `E_PENDING`, zero counts | the null-queue check and the reset | Each refusal must also report zero bytes consumed and produced and leave the destination and its guards unchanged. The scenario prints one line per case and every failing case as `FAIL: refusals <case>: ...`. The six queue scenarios now also check that their final empty dequeue leaves `decoded` at `E_PENDING` with zero counts. No existing check was changed. Negative control: `dstorage_rfc1950_refusals_truncation_control` builds the same check against a build-tree copy of `dstorage_rfc1950.cpp` without `request.SrcSize > ULONG_MAX || `. CMake stops with `FATAL_ERROR` if that text is gone and re-runs when the source file changes (`CMAKE_CONFIGURE_DEPENDS`). The test uses `PASS_REGULAR_EXPRESSION "FAIL: refusals src_over_ulong_max: status 0x8007000d"` instead of `WILL_FAIL`, so it passes only when the check reports this specific defect. A crash does not pass it. When run directly, the control prints `FAIL: refusals src_over_ulong_max: status 0x8007000d consumed=116 produced=768, expected 0x80070057`, passes the other ten cases and exits 1. The change touches `tests/dstorage_rfc1950_check.cpp` (one new function, a `main` branch and one check after the last dequeue) and the `DSTORAGE_SDK_ROOT` block of `CMakeLists.txt` (`refusals` added to the scenario list, plus the control). It also adds a paragraph to "Windows file-to-memory RFC 1950 requests" in `docs/experiments.md`. `src/dstorage_rfc1950.*` is unchanged. ## Verification Commit `eb913fc7` on `cb6f71d4` (`main`), `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260. DirectStorage 1.3.0 NuGet package extracted under `out/dstorage-sdk`. zlib 1.3.1 (`zlib-1.3.1.tar.gz`, SHA-256 `9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23`) was built as a Release `zlibstatic` with `/MD`, and its library and headers were copied under `out/zlib-install`. No GPU is involved; the queue uses a memory destination. ```powershell cmake --preset dev "-DDSTORAGE_SDK_ROOT=$PWD/out/dstorage-sdk" "-DZLIB_ROOT=$PWD/out/zlib-install" "-DZLIB_LIBRARY_RELEASE=$PWD/out/zlib-install/lib/zlibstatic.lib" cmake --build --preset dev --target dstorage_rfc1950_check dstorage_rfc1950_truncation_control ctest --preset dev --no-tests=error -R '^dstorage_rfc1950_' --repeat until-fail:10 # 8/8 passed, 10 repetitions each ``` `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Mutation probe I applied each mutation to `src/dstorage_rfc1950.cpp` alone, rebuilt `dstorage_rfc1950_check` and ran the scenarios, then reverted. "Existing" is the six queue scenarios on the unchanged test file and `CMakeLists.txt`. "With the new cases" adds `refusals` and the empty-dequeue check. For that run I took out the `CMAKE_CONFIGURE_DEPENDS` line, so the control's configure guard would not stop the `SrcSize` mutant. None of this is committed. | Mutant | Existing six | With the new cases | |---|---|---| | format test dropped | **survived** | killed (`format_custom_1`, `format_gdeflate`) | | format `!=` becomes `<` | **survived** | killed (`format_custom_1`) | | `Flags` test dropped | **survived** | killed (`flag_dest_in_upload_heap`) | | `E_NOTIMPL` becomes `E_INVALIDARG` | **survived** | killed | | `!SrcBuffer` dropped | **survived** | killed (`null_src`: `0x8007000d`) | | `!DstBuffer` dropped | **survived** | killed (null write, crash) | | `!SrcSize` dropped | **survived** | killed (`zero_src`) | | `!DstSize` dropped | **survived** | killed (`zero_dst`) | | `SrcSize > ULONG_MAX` dropped (the control) | **survived** | killed (`src_over_ulong_max`) | | size refusal becomes `E_NOTIMPL` | **survived** | killed | | `!queue` dropped | **survived** | killed (null call, crash) | | `decoded` not reset | **survived** | killed (all seven scenarios) | | `used != SrcSize` dropped | killed (`trailing`) | killed | | `written != DstSize` dropped | killed (`oversize`) | killed | | result published under `Id + 1` | killed (timeout or crash) | killed | | empty queue returns `S_OK` | killed | killed | | `S_OK` published for every request | killed | killed | | consumed and produced swapped | killed (`success`) | killed | ## Not pinned or not run - The `DstSize > ULONG_MAX` mutant was not run. Without the bound, `decode` allocates `DstSize` bytes (4 GiB here) before zlib runs, and the Debug heap fills that block. By reading the code, it would return `E_OUTOFMEMORY` or `0x8007000d` instead of `E_INVALIDARG`, so `dst_over_ulong_max` would kill it, but I did not measure that. - The `Z_MEM_ERROR` to `E_OUTOFMEMORY` mapping and the failed allocation path. Neither is reachable without an allocation failure. - `complete_one` passing a failed `GetRequests` through. The DirectStorage queue gives no way to make that call fail. - `flag_dest_in_upload_heap` pins the current refusal of upload-heap destinations. If the codec later accepts them, that case should change with 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. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 19:01:09 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Peer review of PR #1733 at head eb913fc72f8dcd25bba0e4dfeb49ae53f61d34b1.

Summary

  • Scope & hygiene: Changes are confined to CMakeLists.txt (inside if(DSTORAGE_SDK_ROOT)), tests/dstorage_rfc1950_check.cpp, and docs/experiments.md. No src/ files were modified. Title-neutral, MIT clean-room.
  • Test quality: refusals() exercises dstorage_rfc1950::decode() and dstorage_rfc1950::complete_one() directly against real refusal paths (E_NOTIMPL for non-zero custom format, GDEFLATE, and DSTORAGE_CUSTOM_DECOMPRESSION_FLAG_DEST_IN_UPLOAD_HEAP; E_INVALIDARG for null/zero buffers and > ULONG_MAX sizes; E_POINTER and {E_PENDING, 0, 0} reset for a null queue), while also checking guard bytes and zero byte counts. The run() scenarios also verify that the final empty-queue complete_one() resets decoded to E_PENDING with zero counts.
  • Negative control: dstorage_rfc1950_refusals_truncation_control in CMakeLists.txt strips request.SrcSize > ULONG_MAX || from a build-tree copy of src/dstorage_rfc1950.cpp (guarded by CMAKE_CONFIGURE_DEPENDS and FATAL_ERROR if the anchor disappears) and requires PASS_REGULAR_EXPRESSION "FAIL: refusals src_over_ulong_max: status 0x8007000d" so a crash cannot pass.

Checks executed

  • Linux (prep-verify 1733):
    • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py prep-verify 1733 --dir /tmp/rev-x2w-84/1733 --json -> git_diff_check: PASS, docs_links_check: PASS, bidi_controls_check: PASS, py_compile: PASS.
  • Win2025 (win2025 1733):
    • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1733 --targets dstorage_rfc1950_check,dstorage_rfc1950_truncation_control --regex "dstorage_rfc1950_.*" -> failed at build (ninja: error: unknown target 'dstorage_rfc1950_check') because DSTORAGE_SDK_ROOT and ZLIB_ROOT are not provisioned on the Win2025 verification node (C:\x2w\out contains only build, pe-env, tools). Consequently, Win2025 Debug, Release /O2, and the src/dstorage_rfc1950.cpp mutation check could not be executed locally here.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044701230 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1733#pullrequestreview-6044701230). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:04:28Z. **Review:** COMMENTED --- Peer review of PR #1733 at head `eb913fc72f8dcd25bba0e4dfeb49ae53f61d34b1`. ### Summary - **Scope & hygiene**: Changes are confined to `CMakeLists.txt` (inside `if(DSTORAGE_SDK_ROOT)`), `tests/dstorage_rfc1950_check.cpp`, and `docs/experiments.md`. No `src/` files were modified. Title-neutral, MIT clean-room. - **Test quality**: `refusals()` exercises `dstorage_rfc1950::decode()` and `dstorage_rfc1950::complete_one()` directly against real refusal paths (`E_NOTIMPL` for non-zero custom format, `GDEFLATE`, and `DSTORAGE_CUSTOM_DECOMPRESSION_FLAG_DEST_IN_UPLOAD_HEAP`; `E_INVALIDARG` for null/zero buffers and `> ULONG_MAX` sizes; `E_POINTER` and `{E_PENDING, 0, 0}` reset for a null queue), while also checking guard bytes and zero byte counts. The `run()` scenarios also verify that the final empty-queue `complete_one()` resets `decoded` to `E_PENDING` with zero counts. - **Negative control**: `dstorage_rfc1950_refusals_truncation_control` in `CMakeLists.txt` strips `request.SrcSize > ULONG_MAX || ` from a build-tree copy of `src/dstorage_rfc1950.cpp` (guarded by `CMAKE_CONFIGURE_DEPENDS` and `FATAL_ERROR` if the anchor disappears) and requires `PASS_REGULAR_EXPRESSION "FAIL: refusals src_over_ulong_max: status 0x8007000d"` so a crash cannot pass. ### Checks executed - **Linux (`prep-verify 1733`)**: - `python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py prep-verify 1733 --dir /tmp/rev-x2w-84/1733 --json` -> `git_diff_check`: PASS, `docs_links_check`: PASS, `bidi_controls_check`: PASS, `py_compile`: PASS. - **Win2025 (`win2025 1733`)**: - `python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1733 --targets dstorage_rfc1950_check,dstorage_rfc1950_truncation_control --regex "dstorage_rfc1950_.*"` -> failed at build (`ninja: error: unknown target 'dstorage_rfc1950_check'`) because `DSTORAGE_SDK_ROOT` and `ZLIB_ROOT` are not provisioned on the Win2025 verification node (`C:\x2w\out` contains only `build`, `pe-env`, `tools`). Consequently, Win2025 Debug, Release `/O2`, and the `src/dstorage_rfc1950.cpp` mutation check could not be executed locally here. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 20:00:27 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1726
No description provided.