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

Merged
Asimmimx merged 1 commit from upstream-pr/1493 into main 2026-11-24 13:29:20 +00:00
Asimmimx commented 2026-11-24 12:54:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T12:54:08Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582238166 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1493). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T12:54:08Z. --- ## 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).
upstream-sync closed this pull request 2026-11-24 14:02:55 +00:00
tedin7 commented 2026-11-24 14:02:55 +00:00 (Migrated from github.com)

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

Review: COMMENTED


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)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039687299 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1493#pullrequestreview-6039687299). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:04:43Z. **Review:** COMMENTED --- 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`)
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!1486
No description provided.