Skip to content

DirectStorage: validate request sizes and bounds before buffer allocation (#1392) - #1438

Open
hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/dstorage-request-bounds-validation
Open

hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:fix/dstorage-request-bounds-validation

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown

Runtime fix verified with unit tests and RX 9070 XT smoke run.

What is in it

Tested

  • Windows 11 Pro x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT 16 GB, Rust MSVC: cargo test --workspace -- --test-threads=4 passed.

Regression run

main:

xcl-smoke v1
commit: b9b6ea62080cc62fc19e212033372d01c6214e5c
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1678 (PresentX 1678)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14840 MB

PR:

xcl-smoke v1
commit: 370246cdf1990ae47015cd6c0b3268a252b8f96e
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1681 (PresentX 1682)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14845 MB

Not tested

  • In-game world gameplay beyond the 60-second startup/menu smoke run (XCL_NETWORK=0) and NVIDIA / wave32-only GPUs.

AI use

  • AI-assisted implementation and synthetic unit tests; verified with workspace unit tests and local RX 9070 XT smoke run.

@hajduzsolt
hajduzsolt marked this pull request as draft November 24, 2026 16:12
@crosettiremi

crosettiremi commented Nov 24, 2026 •

Copy link
Copy Markdown

Independent downstream observation on Windows / RX 7900 XT. A cold-cache build based on main 9e3831e with #789 and #1514 streamed title assets after account selection, then exited 0xc0000409 under a 28 GiB Windows job limit. Peak sampled process commit was 28,088 MB. A stack scan on the terminating thread with the matching XCL PDB found the Rust OOM handler, miniz_oxide inflate, and the DirectStorage queue worker. The exact request and requested allocation size are unknown.

Your source-buffer checks apply cleanly to that build. There is a separate allocation in the zlib output path: decompress_to_vec_zlib_with_limit bounds length but allocates the output infallibly. I tested a local fallible-output variant with valid zlib data, exact and unspecified intermediate lengths, zero padding, checksum failure, and an injected allocation refusal during buffer growth. The focused fixture passed and the refusal returned E_OUTOFMEMORY. Hardware validation of the combined changes is pending.

Hardware follow-up on the same RX 7900 XT, cold application cache, 28 GiB job limit. With the source checks plus fallible zlib output, the release built and all 19 downstream DirectStorage tests passed. Run 91 selected Player1 at 49 s. In the 60–150 s samples, XCL counted 88,084 attempted requests and 109 failures. Destination tracing found requests with options 0x200001 (file/zlib to physical pages) still carrying a zero page number when the worker tried to write. The last positive present sample ended at 174.217 s. The final captured frame was dark. Process exit was again 0xc0000409 and peak sampled process commit was 28,566 MB. This time the matching-PDB stack scan showed the allocator failure in Chain::detile_level, title_textures::subresources and a subresources_on worker. This run did not establish that the zlib allocator itself encountered pressure, and changing it did not eliminate process-level memory exhaustion.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@gut0to gut0to left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newer smoke blocks and test results are useful, but the description still contains an earlier duplicated Tested/Regression section with a literal \text placeholder and a pending-human-verification note. It reports different counts and empty smoke blocks, which conflicts with the later complete results and makes the current evidence ambiguous. Could you remove the stale section and leave one canonical Tested/Regression report? AI-assisted review; I checked both sections in the current description.

@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 19:01
@hajduzsolt

Copy link
Copy Markdown
Author

Thanks for flagging the duplicate section. The earlier Tested/Regression text and pending placeholder are stale; the later Tested/Regression sections contain the newer results. I have left the smoke-containing description intact for the automated verifier, so the duplicate still needs cleanup there.

@hajduzsolt

Copy link
Copy Markdown
Author

Thanks for flagging this. I removed the stale duplicate section and preserved both existing smoke blocks verbatim.

@hajduzsolt
hajduzsolt marked this pull request as draft November 24, 2026 20:08
@hajduzsolt
hajduzsolt force-pushed the fix/dstorage-request-bounds-validation branch from 8bfe682 to 370246c Compare November 24, 2026 20:08
@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 20:11
@gigabyteZ390

Copy link
Copy Markdown

Tested 370246cdf1990ae47015cd6c0b3268a252b8f96e (head of #1438) against its base b9b6ea62080cc62fc19e212033372d01c6214e5c, on NVIDIA (wave32), the case listed under Not tested.

Tested

  • NVIDIA GeForce RTX 3070 8 GB, driver 621.40; Intel Core i9-9900K, 32 GB; Windows 11 Pro 26H2 build 26300.9974; Rust 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2609; debug for the tests, release for the smoke runs
  • .\scripts\test.ps1 on the head, with XCL_SAMPLE_RPF / _DLLS / _TTPF set: 890 passed, 0 failed, 42 ignored; unvalidated_request_sizes_rejected_without_allocating passes
  • SKIPPED on this adapter: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows) – the same three as on main
  • scripts/smoke.ps1, a retail title, 60 s, base and head each run twice and the second run recorded (shader caches warm):

base:

xcl-smoke v1
commit: b9b6ea62080cc62fc19e212033372d01c6214e5c
gpu: NVIDIA GeForce RTX 3070
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1611 (PresentX 1611)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14724 MB

PR:

xcl-smoke v1
commit: 370246cdf1990ae47015cd6c0b3268a252b8f96e
gpu: NVIDIA GeForce RTX 3070
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14729 MB
  • DirectStorage in those two runs (xcl.log activity lines): 9767 requests, 650 MB, 0 failed on the base and on the head alike. The logged requests were all file sources (zlib or plain); no physical-page request was logged.

The new test passes without the fix. Applied alone (only the test hunk) onto b9b6ea6, cargo test -p xcl --lib unvalidated_request_sizes_rejected_without_allocating gives 1 passed. Both cases already returned these HRESULTs before the PR: a file read past its end got E_END_OF_FILE from read_exact_at, and the unreadable memory source got E_ACCESS_VIOLATION; the base just allocated source_size bytes first (dstorage.rs:880 and :897 on b9b6ea6). The test checks the HRESULTs, not that nothing is allocated before the checks, so it does not show the fix.

Not tested

  • A real oversized or out-of-bounds request: the title sent none in 60 s (0 failed on the base too), so the new rejection paths were not reached by it
  • The cold-cache out-of-memory exit reported in the comments above: not reproduced in these runs
  • Physical-page sources and destinations, AMD (the author's RX 9070 XT run covers it), GPUs with native wave64

Written by Claude Code (Claude Opus 5.5) from runs on this machine; checked before posting.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #1381 #1785 solves the same problem (for #1392) in a different way: #1607, group D54. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@anes66

anes66 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

CPU-only DirectStorage error-path verification on exact head 370246cdf1990ae47015cd6c0b3268a252b8f96e passed. Optional companion b6a0a3d is directly on that head and adds one test only.

Tested

  • Windows 10 Pro 19045, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug. No GPU, DXC or title execution.
  • An isolated child has a 64 MiB Windows process-commit cap. The fixture file has a logical length of 128 MiB; its contents are never read. A BC1-shaped request passes Request::check(false) and targets an eight-byte sentinel buffer.
  • A source span starting one byte past the last valid starting offset returns E_END_OF_FILE before the 128 MiB source allocation. The in-bounds span instead returns E_OUTOFMEMORY; both leave every destination byte unchanged. The real D3D12 device pointer stays null.
  • cargo test --locked -p xcl --lib file_bounds_precede_allocator_refusal_and_refusal_preserves_destination -j 2 -- --nocapture --test-threads=1: 1 passed / 0 failed / 0 ignored / 0 skips.
  • Existing unvalidated_request_sizes_rejected_without_allocating filter: 1 passed / 0 failed / 0 ignored / 0 skips.
  • Negative controls: bypassing the file-end check produces E_OUTOFMEMORY instead of E_END_OF_FILE; replacing the fallible file-source buffer with the original vec! aborts the child with memory allocation of 134217728 bytes failed. Both cause the parent test to fail. Restored before final passing runs and commit.

Not tested
Full queue/status propagation for the new case (it calls execute with an explicit synthetic FileInner), compressed contents, zlib/BCPack intermediate/output allocation failures, physical-page destinations, actual system memory pressure, release, GPU/workspace suite, retail smoke or newer-main integration. No claim that this PR fixes a particular retail crash. The job cap is child-only and does not change the parent or system configuration.

AI use: Codex (GPT-6; exact variant unavailable) wrote the test and temporary controls, ran CPU verification and prepared this report.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DirectStorage: execute allocates 4-12 GiB from unvalidated request sizes before checking source/file/pages

8 participants