Reject DirectStorage reads past EOF before allocating staging #1278
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1285"
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 R0Y00 on 2026-11-24T06:46:31Z.
Refs #1144.
A file request could allocate its entire declared source size before finding that the read was past EOF. The worker now obtains the current size from its open handle and checks both the offset and the remaining span before resizing the staging vector. A read ending exactly at EOF succeeds. ReadFile must still return the entire requested count before any destination write.
The new file-range check uses a five-byte temporary file. It checks the last three real bytes, a one-byte overrun, a request starting at EOF, a 64 MiB request, a wrapping 64-bit offset and a failed size query. All rejected cases preserve the size, capacity and contents of the staging vector. The existing source-built queue consumer now also checks the HRESULT and guarded destination for an exact-end read, an overrun and an empty request with an out-of-file offset.
Windows 11 25H2 build 26200.9974, MSVC Release, commit
de0754bf:Both tests passed in 0.86 seconds. No capability skips.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:52:47Z.
Review: COMMENTED
Reviewed at
de0754bfb7b4560e8dd9d682b9f4b260b9ffb424.Verification
Linux (worktree from
origin/main):git diff --check origin/main...HEAD— cleanpython -B tests/docs_links_check.py— passed (16 Markdown files, 286 links)python -B tests/bidi_controls_check.py— passed (1080 tracked files)Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at
de0754bfb7b4560e8dd9d682b9f4b260b9ffb424:--preset dev):cmake --build --preset dev --target startup_storage_file_range startup_stub_consumer -- -j 6):26.03s(configure1.75s)ctest --preset dev -R 'startup_storage_file_range|startup_stub_consumer' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.09s:startup_storage_file_range0.02s;startup_stub_consumercompiled/linked cleanly)/O2(--preset release):cmake --build --preset release --target startup_storage_file_range startup_stub_consumer -- -j 6):38.30s(configure1.51s)ctest --preset release -R 'startup_storage_file_range|startup_stub_consumer' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.08s:startup_storage_file_range0.02s;startup_stub_consumercompiled/linked cleanly)Findings
x2w_startup::read_storage_file(src/startup_stubs/dstorage_file_read.h) uses an overflow-safe bounds check (offset > size || count > size - offset) afterGetFileSizeExand beforestaging.resize(count), preventing large allocations on invalid offsets/counts.tests/startup_storage_file_range.cppandtests/startup_stub_consumer.cppcover exact-EOF reads, out-of-range/overflowing offsets,INVALID_HANDLE_VALUE, preservation ofstagingcontents/capacity on rejected ranges, and destination preservation on failed queue requests.stagingis preserved when the pre-allocation bounds check fails, whereas ifReadFileitself fails or returns a short read (e.g., concurrent truncation) afterstaging.resize(count),stagingwill have been resized. Fine forxcrdapi.cpp's localpackedvector, just worth keeping in mind if reused with persistent buffers.