startup: check the DirectStorage file read above 4 GiB #1493

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

@⁠Asimmimx on GitHub · 2026-11-24 12:54 UTC · original
Asimmimx:startup/dstorage-file-read-check → main · +124 −0 · 3 files · 1 commits · merged 2026-11-24 13:29 UTC

Change

Refs #1149. This adds a check for src/startup_stubs/dstorage_file_read.h, the DirectStorage stand-in's ranged file read used from xcrdapi.cpp. The header splits the 64-bit offset across OVERLAPPED::Offset/OffsetHigh and bounds the range against the 64-bit file size.

The three CPU tests that reach it are startup_storage_file_range, startup_stubs and startup_storage_directory_batch. None of them reads at an offset of 2 GiB or more. As a result, these three mutants left all three tests passing:

  • clearing OffsetHigh;
  • shifting by 31 instead of 32;
  • taking the file size from LowPart.

Under each of them, a read at 0x100000010 returns the bytes at 0x10.

startup_dstorage_file_read includes only the header. It makes a temporary sparse file of 4 GiB + 20 bytes and writes four 4-byte runs at hand-written positions:

  • 0x10;
  • 0x80000010;
  • 0xFFFFFFFE, which crosses 4 GiB;
  • 0x100000010, which ends the file.

It reads each run back and compares the bytes. It also checks that two reads past the end of the file above 4 GiB are refused and leave the staging buffer and its capacity unchanged. The file has the delete-on-close flag and occupies only a few clusters. If the temporary folder cannot hold sparse files, the test exits 77 before writing anything.

startup_dstorage_file_read_alias_control runs --mutate alias, which expects the 0x10 bytes at the high offset, and must fail (WILL_FAIL). Both tests have SKIP_RETURN_CODE 77.

The change is test, CMake and docs/startup-runtime.md (the "DirectStorage file ranges" entry) only. The CMake block follows startup_storage_file_range.

Verification

Commit 93672b99 (main) plus this change, dev preset (Debug), Windows 11 Pro build 26300.9974, NTFS %TEMP%, MSVC 19.51.36260, Windows SDK 10.0.26100.0.

ctest --preset dev --no-tests=error -R '^startup_(dstorage_file_read(_alias_control)?|storage_file_range|storage_directory_batch|stubs)$' -V
startup_dstorage_file_read ................. Passed   (offsets above 2 and 4 GiB exact)
startup_dstorage_file_read_alias_control ... Passed   (b1 b2 b3 b4 read where the control expects a1 a2 a3 a4)
startup_storage_file_range / startup_storage_directory_batch / startup_stubs  Passed

The run takes about 0.13 s, and free space on the drive was unchanged after it. tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed.

Mutation probe

I applied each mutation to the header alone, rebuilt the affected targets, ran the three existing tests, then reverted. None of this is committed.

Mutant Existing 3 startup_dstorage_file_read
control: drop the count > size - offset check killed fails
offset > size → >= survived survived (not pinned, see below)
count > size - offset → >= (range ending at EOF refused) killed fails
count > size - offset → count > size killed fails
OffsetHigh = 0 survived fails
offset >> 32 → offset >> 31 survived fails
low and high halves swapped killed fails
drop && read == count survived survived (not covered)
staging buffer resized before the range check killed fails
file size from length.LowPart survived fails
drop length.QuadPart < 0 survived survived (cannot happen)

The three survivors are not covered on purpose:

  • >= at the end of the file. It would only refuse a zero-byte read exactly at the end, and the only caller filters out zero-size requests.
  • Short read. It needs the file to shrink between the size check and the read, which a single-threaded test cannot cause deterministically.
  • Negative size. It cannot happen.

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).

**@⁠Asimmimx** on GitHub · 2026-11-24 12:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1493) `Asimmimx:startup/dstorage-file-read-check` → `main` · +124 −0 · 3 files · 1 commits · merged 2026-11-24 13:29 UTC ## Change Refs #1149. This adds a check for `src/startup_stubs/dstorage_file_read.h`, the DirectStorage stand-in's ranged file read used from `xcrdapi.cpp`. The header splits the 64-bit offset across `OVERLAPPED::Offset`/`OffsetHigh` and bounds the range against the 64-bit file size. The three CPU tests that reach it are `startup_storage_file_range`, `startup_stubs` and `startup_storage_directory_batch`. None of them reads at an offset of 2 GiB or more. As a result, these three mutants left all three tests passing: - clearing `OffsetHigh`; - shifting by 31 instead of 32; - taking the file size from `LowPart`. Under each of them, a read at 0x100000010 returns the bytes at 0x10. `startup_dstorage_file_read` includes only the header. It makes a temporary sparse file of 4 GiB + 20 bytes and writes four 4-byte runs at hand-written positions: - 0x10; - 0x80000010; - 0xFFFFFFFE, which crosses 4 GiB; - 0x100000010, which ends the file. It reads each run back and compares the bytes. It also checks that two reads past the end of the file above 4 GiB are refused and leave the staging buffer and its capacity unchanged. The file has the delete-on-close flag and occupies only a few clusters. If the temporary folder cannot hold sparse files, the test exits 77 before writing anything. `startup_dstorage_file_read_alias_control` runs `--mutate alias`, which expects the 0x10 bytes at the high offset, and must fail (`WILL_FAIL`). Both tests have `SKIP_RETURN_CODE 77`. The change is test, CMake and `docs/startup-runtime.md` (the "DirectStorage file ranges" entry) only. The CMake block follows `startup_storage_file_range`. ## Verification Commit `93672b99` (`main`) plus this change, `dev` preset (Debug), Windows 11 Pro build 26300.9974, NTFS `%TEMP%`, MSVC 19.51.36260, Windows SDK 10.0.26100.0. ```powershell ctest --preset dev --no-tests=error -R '^startup_(dstorage_file_read(_alias_control)?|storage_file_range|storage_directory_batch|stubs)$' -V ``` ```text startup_dstorage_file_read ................. Passed (offsets above 2 and 4 GiB exact) startup_dstorage_file_read_alias_control ... Passed (b1 b2 b3 b4 read where the control expects a1 a2 a3 a4) startup_storage_file_range / startup_storage_directory_batch / startup_stubs Passed ``` The run takes about 0.13 s, and free space on the drive was unchanged after it. `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Mutation probe I applied each mutation to the header alone, rebuilt the affected targets, ran the three existing tests, then reverted. None of this is committed. | Mutant | Existing 3 | `startup_dstorage_file_read` | |---|---|---| | control: drop the `count > size - offset` check | killed | fails | | `offset > size` → `>=` | survived | survived (not pinned, see below) | | `count > size - offset` → `>=` (range ending at EOF refused) | killed | fails | | `count > size - offset` → `count > size` | killed | fails | | `OffsetHigh = 0` | **survived** | fails | | `offset >> 32` → `offset >> 31` | **survived** | fails | | low and high halves swapped | killed | fails | | drop `&& read == count` | survived | survived (not covered) | | staging buffer resized before the range check | killed | fails | | file size from `length.LowPart` | **survived** | fails | | drop `length.QuadPart < 0` | survived | survived (cannot happen) | The three survivors are not covered on purpose: - **`>=` at the end of the file.** It would only refuse a zero-byte read exactly at the end, and the only caller filters out zero-size requests. - **Short read.** It needs the file to shrink between the size check and the read, which a single-threaded test cannot cause deterministically. - **Negative size.** It cannot happen. ## 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).
src/startup_stubs/dstorage_file_read.h reads a DirectStorage file
request into the staging buffer through an OVERLAPPED position split
into low and high 32-bit halves. Its only direct check,
startup_storage_file_range, uses a 5-byte file, and the stand-in tests
that load XCRDAPI.dll (startup_stubs, startup_storage_directory_batch)
read small synthetic files. Single-point mutants that zero the high
half, shift it by 31 instead of 32, or take the file size from its low
32 bits left all three passing.

startup_dstorage_file_read writes four 4-byte runs into a sparse
temporary file of 4 GiB + 20 bytes: at 0x10, above 2 GiB, across
4 GiB and at the end of the file 4 GiB above the first run. It reads
each back with hand-written expected bytes and checks that ranges one
byte past EOF above 4 GiB are rejected without touching the staging
buffer. Each of the three mutants above now fails it. The
startup_dstorage_file_read_alias_control run expects the low run's
bytes at the high offset and must fail. Both exit 77 where the
temporary folder does not take sparse files, before anything is written.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:11:30 +00:00
github manually merged commit b6522d1935 into gh-pr/1493/base 2026-11-26 23:11:31 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 13:04 UTC · original · reviewed

Peer review of PR #1493 (b6522d1935a9f73ff782e177ffb728b590084fe9).

Code & Diff Audit

  • Scope: Focused to CMakeLists.txt, docs/startup-runtime.md, and tests/startup_dstorage_file_read_check.cpp; src/startup_stubs/dstorage_file_read.h is untouched.
  • Correctness & Edge Cases:
    • Uses a FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE sparse file (FSCTL_SET_SPARSE, skipping cleanly with exit code 77 if the temp filesystem lacks sparse support) sized to 0x100000014 (4 GiB + 20 bytes).
    • Writes four 4-byte runs using literal OVERLAPPED halves (0x10, 0x80000010, 0xFFFFFFFE crossing 4 GiB, and 0x100000010 at OffsetHigh = 1 ending at EOF) and verifies exact readback via x2w_startup::read_storage_file.
    • Verifies out-of-range reads past EOF above 4 GiB (0x100000011 count 4, 0x100000015 count 1) return false without modifying the staging vector's contents or capacity.
    • --mutate alias negative control (startup_dstorage_file_read_alias_control, WILL_FAIL TRUE) catches OffsetHigh aliasing to 0x10.
  • Hygiene: tests/docs_links_check.py, tests/bidi_controls_check.py, and git diff --check origin/main...HEAD all pass on Linux. Title-neutral.

Win2025 Verification

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit b6522d1935a9f73ff782e177ffb728b590084fe9:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_dstorage_file_read_check startup_storage_file_range -- -j 6): 4.01s (configure 1.72s)
    • Test (ctest --preset dev -R '^startup_(dstorage_file_read(_alias_control)?|storage_file_range)$' --parallel 4 --no-tests=error --output-on-failure): 3/3 passed (0.10s: startup_storage_file_range 0.02s, startup_dstorage_file_read 0.02s, startup_dstorage_file_read_alias_control 0.01s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_dstorage_file_read_check startup_storage_file_range -- -j 6): 1.27s (configure 1.80s)
    • Test (ctest --preset release -R '^startup_(dstorage_file_read(_alias_control)?|storage_file_range)$' --parallel 4 --no-tests=error --output-on-failure): 3/3 passed (0.09s: startup_storage_file_range 0.02s, startup_dstorage_file_read 0.02s, startup_dstorage_file_read_alias_control 0.01s)
**@⁠tedin7** on GitHub · 2026-11-24 13:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1493#pullrequestreview-6039687299) · **reviewed** Peer review of PR #1493 (`b6522d1935a9f73ff782e177ffb728b590084fe9`). ### Code & Diff Audit - **Scope**: Focused to `CMakeLists.txt`, `docs/startup-runtime.md`, and `tests/startup_dstorage_file_read_check.cpp`; `src/startup_stubs/dstorage_file_read.h` is untouched. - **Correctness & Edge Cases**: - Uses a `FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE` sparse file (`FSCTL_SET_SPARSE`, skipping cleanly with exit code `77` if the temp filesystem lacks sparse support) sized to `0x100000014` (4 GiB + 20 bytes). - Writes four 4-byte runs using literal `OVERLAPPED` halves (`0x10`, `0x80000010`, `0xFFFFFFFE` crossing 4 GiB, and `0x100000010` at `OffsetHigh = 1` ending at EOF) and verifies exact readback via `x2w_startup::read_storage_file`. - Verifies out-of-range reads past EOF above 4 GiB (`0x100000011` count 4, `0x100000015` count 1) return `false` without modifying the staging vector's contents or capacity. - `--mutate alias` negative control (`startup_dstorage_file_read_alias_control`, `WILL_FAIL TRUE`) catches `OffsetHigh` aliasing to `0x10`. - **Hygiene**: `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, and `git diff --check origin/main...HEAD` all pass on Linux. Title-neutral. ### Win2025 Verification Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `b6522d1935a9f73ff782e177ffb728b590084fe9`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target startup_dstorage_file_read_check startup_storage_file_range -- -j 6`): `4.01s` (configure `1.72s`) - Test (`ctest --preset dev -R '^startup_(dstorage_file_read(_alias_control)?|storage_file_range)$' --parallel 4 --no-tests=error --output-on-failure`): **3/3 passed** (`0.10s`: `startup_storage_file_range` `0.02s`, `startup_dstorage_file_read` `0.02s`, `startup_dstorage_file_read_alias_control` `0.01s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target startup_dstorage_file_read_check startup_storage_file_range -- -j 6`): `1.27s` (configure `1.80s`) - Test (`ctest --preset release -R '^startup_(dstorage_file_read(_alias_control)?|storage_file_range)$' --parallel 4 --no-tests=error --output-on-failure`): **3/3 passed** (`0.09s`: `startup_storage_file_range` `0.02s`, `startup_dstorage_file_read` `0.02s`, `startup_dstorage_file_read_alias_control` `0.01s`)
This discussion has been locked. Commenting is limited to contributors.
No description provided.