startup: check the DirectStorage file read above 4 GiB #1486
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1493"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 fromxcrdapi.cpp. The header splits the 64-bit offset acrossOVERLAPPED::Offset/OffsetHighand bounds the range against the 64-bit file size.The three CPU tests that reach it are
startup_storage_file_range,startup_stubsandstartup_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:OffsetHigh;LowPart.Under each of them, a read at 0x100000010 returns the bytes at 0x10.
startup_dstorage_file_readincludes only the header. It makes a temporary sparse file of 4 GiB + 20 bytes and writes four 4-byte runs at hand-written positions: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_controlruns--mutate alias, which expects the 0x10 bytes at the high offset, and must fail (WILL_FAIL). Both tests haveSKIP_RETURN_CODE 77.The change is test, CMake and
docs/startup-runtime.md(the "DirectStorage file ranges" entry) only. The CMake block followsstartup_storage_file_range.Verification
Commit
93672b99(main) plus this change,devpreset (Debug), Windows 11 Pro build 26300.9974, NTFS%TEMP%, MSVC 19.51.36260, Windows SDK 10.0.26100.0.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.pyandgit diff --checkpassed.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.
startup_dstorage_file_readcount > size - offsetcheckoffset > size→>=count > size - offset→>=(range ending at EOF refused)count > size - offset→count > sizeOffsetHigh = 0offset >> 32→offset >> 31&& read == countlength.LowPartlength.QuadPart < 0The 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.Checklist
AI-assisted (Claude Code).
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
CMakeLists.txt,docs/startup-runtime.md, andtests/startup_dstorage_file_read_check.cpp;src/startup_stubs/dstorage_file_read.his untouched.FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSEsparse file (FSCTL_SET_SPARSE, skipping cleanly with exit code77if the temp filesystem lacks sparse support) sized to0x100000014(4 GiB + 20 bytes).OVERLAPPEDhalves (0x10,0x80000010,0xFFFFFFFEcrossing 4 GiB, and0x100000010atOffsetHigh = 1ending at EOF) and verifies exact readback viax2w_startup::read_storage_file.0x100000011count 4,0x100000015count 1) returnfalsewithout modifying the staging vector's contents or capacity.--mutate aliasnegative control (startup_dstorage_file_read_alias_control,WILL_FAIL TRUE) catchesOffsetHighaliasing to0x10.tests/docs_links_check.py,tests/bidi_controls_check.py, andgit diff --check origin/main...HEADall pass on Linux. Title-neutral.Win2025 Verification
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
b6522d1935a9f73ff782e177ffb728b590084fe9:--preset dev):cmake --build --preset dev --target startup_dstorage_file_read_check startup_storage_file_range -- -j 6):4.01s(configure1.72s)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_range0.02s,startup_dstorage_file_read0.02s,startup_dstorage_file_read_alias_control0.01s)/O2(--preset release):cmake --build --preset release --target startup_dstorage_file_read_check startup_storage_file_range -- -j 6):1.27s(configure1.80s)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_range0.02s,startup_dstorage_file_read0.02s,startup_dstorage_file_read_alias_control0.01s)