DirectStorage: zero-pad short uncompressed requests to destination size (#1488) #1615

Open
slopgobblercobbler wants to merge 1 commit from upstream-pr/1625 into main
slopgobblercobbler commented 2026-11-24 18:23:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T18:23:24Z.


Summary

Pads short uncompressed DirectStorage requests to destination size in crates/xcl/src/hle/dstorage.rs (Issue #1488, finding XCL-BT-004):

  1. Uncompressed request payload safety:
    • In uncompressed DirectStorage requests (!r.zlib() && bc == 0), titles may specify source_size < destination_size (r.source_size < n).
    • Previously, src was allocated with length r.source_size and assigned directly to payload.
    • On physical page writes (r.dest_physical_pages()), &payload[..n] panicked with a slice index out-of-bounds error.
    • On virtual memory writes, std::ptr::copy_nonoverlapping(payload.as_ptr(), r.destination, n) caused a heap-buffer over-read reading past the end of payload.
    • Enforced if bc == 0 && !r.zlib() && payload.len() < n { payload.resize(n, 0); }, zero-padding payload to the full requested destination size n.
  2. Unit tests:
    • Added uncompressed_request_with_short_source_is_zero_padded in dstorage.rs asserting clean completion without panic or buffer over-read across both virtual memory and physical page destinations, verifying exact source data copying and zero-padding of remaining destination bytes.

Changes

  • crates/xcl/src/hle/dstorage.rs:
    • Zero-pad uncompressed payload when source_size < destination_size.
    • Synthetic unit test verifying padding and preventing slice panic/heap over-read.

Tested

  • Windows 11 x64, Rust MSVC stable.
  • cargo test -p xcl -- dstorage: 18 passed, 0 failed.
  • Clean diff: zero trailing whitespace, clean rebase on latest upstream/main, GPL-2.0-only compliant, zero retail game data or keys.

Not Tested

  • Real-time retail title streaming under DirectStorage compression queues.

AI Use

Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity

<!-- greyfinch-sync:ivall/xcl:issue:5477929379 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1625). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-24T18:23:24Z. --- ## Summary Pads short uncompressed DirectStorage requests to destination size in `crates/xcl/src/hle/dstorage.rs` (Issue #1488, finding `XCL-BT-004`): 1. **Uncompressed request payload safety**: - In uncompressed DirectStorage requests (`!r.zlib() && bc == 0`), titles may specify `source_size < destination_size` (`r.source_size < n`). - Previously, `src` was allocated with length `r.source_size` and assigned directly to `payload`. - On physical page writes (`r.dest_physical_pages()`), `&payload[..n]` panicked with a slice index out-of-bounds error. - On virtual memory writes, `std::ptr::copy_nonoverlapping(payload.as_ptr(), r.destination, n)` caused a heap-buffer over-read reading past the end of `payload`. - Enforced `if bc == 0 && !r.zlib() && payload.len() < n { payload.resize(n, 0); }`, zero-padding `payload` to the full requested destination size `n`. 2. **Unit tests**: - Added `uncompressed_request_with_short_source_is_zero_padded` in `dstorage.rs` asserting clean completion without panic or buffer over-read across both virtual memory and physical page destinations, verifying exact source data copying and zero-padding of remaining destination bytes. ## Changes - `crates/xcl/src/hle/dstorage.rs`: - Zero-pad uncompressed payload when `source_size < destination_size`. - Synthetic unit test verifying padding and preventing slice panic/heap over-read. ## Tested - Windows 11 x64, Rust MSVC stable. - `cargo test -p xcl -- dstorage`: 18 passed, 0 failed. - Clean diff: zero trailing whitespace, clean rebase on latest `upstream/main`, GPL-2.0-only compliant, zero retail game data or keys. ## Not Tested - Real-time retail title streaming under DirectStorage compression queues. ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
Anon64 commented 2026-11-24 21:08:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T19:33:20Z.


Regression run for this PR: head 58fa588, based on main 9e3831e. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 9e3831e:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1536 (PresentX 1536)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 97380 MB

this PR:

xcl-smoke v1
commit: 58fa588e247dd34f70a2edb5c35c8a08aee47679
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1530 (PresentX 1530)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 103101 MB

No device removals or crashes; 99 % of main's frames, 105 % of its peak commit.

Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies from run to run, so it says little about this PR.

Not tested: the whole suite; whether the title reaches the changed code in these 60 s.

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

<!-- greyfinch-sync:ivall/xcl:comment:7142264784 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1625#issuecomment-7142264784). Originally posted by [Anon64](https://github.com/Anon64) on 2026-11-24T19:33:20Z. --- Regression run for this PR: head `58fa588`, based on `main` `9e3831e`. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, `XCL_NETWORK=0`, A pressed every 4 s from 20 s, `scripts/smoke.ps1` on a retail title for 60 s, in one batch with the `main` run. main `9e3831e`: ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1536 (PresentX 1536) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 97380 MB ``` this PR: ``` xcl-smoke v1 commit: 58fa588e247dd34f70a2edb5c35c8a08aee47679 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1530 (PresentX 1530) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 103101 MB ``` No device removals or crashes; 99 % of main's frames, 105 % of its peak commit. Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies from run to run, so it says little about this PR. **Not tested:** the whole suite; whether the title reaches the changed code in these 60 s. Written with Claude Code (Claude Opus 5.5) from runs on this machine.
DavidM1911 commented 2026-11-24 21:09:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T20:46:38Z.


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

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

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7144041383 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1625#issuecomment-7144041383). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T20:46:38Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
JJAutoCompare commented 2026-11-25 05:08:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T05:00:24Z.


PR #1625 Windows verification

Tested clean detached head 58fa588e247dd34f70a2edb5c35c8a08aee47679 on STOR-WINLAB, Windows 11 Enterprise Evaluation x64 (10.0.26200, build 26200). The guest reports an AuthenticAMD processor (family 23, model 113, stepping 0, ~3.9 GHz) and an Intel Arc A770 with driver 32.0.101.9175. DXC was 1.9.2609.5. Rust was rustc 1.100.0 (0ef1bc386 2026-11-09), x86_64-pc-windows-msvc. The dev and test profiles ran with debug info and incremental compilation disabled.

Tested

  • cargo build --workspace completed successfully.
  • cargo test --workspace --no-run completed successfully and produced 19 test executables.
  • cargo test -p xcl --lib hle::dstorage -- --nocapture --test-threads=1 --skip hle::dstorage::tests::error_record_has_the_failed_requests_offset_source_size_and_tag ran outside the Arc mutex with XCL_ADAPTER=NONE_CPU_ONLY. 17 passed, 0 failed, 0 ignored, 0 SKIPPED markers, 732 filtered out.
  • The PR changes only crates/xcl/src/hle/dstorage.rs. Its regression test verified that an uncompressed memory request preserved all 40 source bytes and wrote 48 zero bytes to fill the 88-byte destination. The log confirms execution of both the virtual-memory and mapped physical-page cases.

Not tested

Execution covered the focused CPU DirectStorage tests only, with the rest of the workspace compiled. The full workspace GPU suite and retail-title smoke runs were omitted. One existing DirectStorage test was filtered out because it deletes its temporary file fixture. Retail BCPack samples were omitted.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1625-focused.log and published.

<!-- greyfinch-sync:ivall/xcl:comment:7153361311 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1625#issuecomment-7153361311). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-25T05:00:24Z. --- # PR #1625 Windows verification Tested clean detached head `58fa588e247dd34f70a2edb5c35c8a08aee47679` on STOR-WINLAB, Windows 11 Enterprise Evaluation x64 (10.0.26200, build 26200). The guest reports an AuthenticAMD processor (family 23, model 113, stepping 0, ~3.9 GHz) and an Intel Arc A770 with driver 32.0.101.9175. DXC was 1.9.2609.5. Rust was rustc 1.100.0 (0ef1bc386 2026-11-09), x86_64-pc-windows-msvc. The dev and test profiles ran with debug info and incremental compilation disabled. **Tested** - `cargo build --workspace` completed successfully. - `cargo test --workspace --no-run` completed successfully and produced 19 test executables. - `cargo test -p xcl --lib hle::dstorage -- --nocapture --test-threads=1 --skip hle::dstorage::tests::error_record_has_the_failed_requests_offset_source_size_and_tag` ran outside the Arc mutex with `XCL_ADAPTER=NONE_CPU_ONLY`. 17 passed, 0 failed, 0 ignored, 0 SKIPPED markers, 732 filtered out. - The PR changes only `crates/xcl/src/hle/dstorage.rs`. Its regression test verified that an uncompressed memory request preserved all 40 source bytes and wrote 48 zero bytes to fill the 88-byte destination. The log confirms execution of both the virtual-memory and mapped physical-page cases. **Not tested** Execution covered the focused CPU DirectStorage tests only, with the rest of the workspace compiled. The full workspace GPU suite and retail-title smoke runs were omitted. One existing DirectStorage test was filtered out because it deletes its temporary file fixture. Retail BCPack samples were omitted. **AI use** T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1625-focused.log` and published.
oni-swr commented 2026-11-26 19:12:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-26T19:12:51Z.


AMD Windows test report for head 58fa588e247dd34f70a2edb5c35c8a08aee47679 (exact head, clean detached checkout, no local changes). Base: main 9e3831e1f570d3646e53ab753b19ec07eb8f1485 (the merge base; the PR is not merged with current main).

Tested

  • AMD Radeon RX 7800 XT (RDNA3, driver 32.0.31035.1003), Ryzen 7 5700X3D, 64 GB, Windows 11 25H2 (26200), Rust 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (Windows Kit 10.0.26100.0). XCL_ADAPTER unset, so the physical GPU was used, not WARP. Own target dir, rebuilt from scratch for this head.
  • cargo build --workspace -j 4: ok.
  • cargo test --workspace -j 4 --no-fail-fast -- --test-threads=4 --nocapture (debug): 777 passed, 0 failed, 41 ignored over 20 test binaries. One SKIPPED line: heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows. The new hle::dstorage::tests::uncompressed_request_with_short_source_is_zero_padded passes. At this head the tree has no fuzz_tests, so the known AMD fuzz failure (#2115) does not come up.
  • 60 s smoke (scripts/smoke.ps1 of each commit, release builds, title run from a local copy): base 9e3831e twice, then this head, in the order base, PR, base:
run frames shown peak commit removals / crashes
base 9e3831e, run 1 1458 17520 MB 0 / 0
this head 58fa588 1464 18086 MB 0 / 0
base 9e3831e, run 2 1456 16579 MB 0 / 0
xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: AMD Radeon RX 7800 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1456 (PresentX 1456)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16579 MB
xcl-smoke v1
commit: 58fa588e247dd34f70a2edb5c35c8a08aee47679
gpu: AMD Radeon RX 7800 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1464 (PresentX 1464)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18086 MB

The older smoke.ps1 at these commits prints the folder name as title:; I replaced it with retail-title in the blocks above and changed nothing else. Peak commit varies by about 1.5 GB between runs of the same commit here (base: 17520 and 16579 MB), so the 18086 MB of this head is within that spread, not a measured increase.

Not tested

  • The merge with current main (8b957bec): the suite and the smoke ran on this head and its merge base only.
  • A title read that is shorter than its request (the case the PR fixes): the 60 s smoke does not show that path being hit.
  • NVIDIA, Intel, Linux/Wine, AMD RDNA2/RDNA4.

AI use: Claude Code (Claude Sonnet 5.5) ran the tests and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7201320335 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1625#issuecomment-7201320335). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T19:12:51Z. --- AMD Windows test report for head `58fa588e247dd34f70a2edb5c35c8a08aee47679` (exact head, clean detached checkout, no local changes). Base: `main` `9e3831e1f570d3646e53ab753b19ec07eb8f1485` (the merge base; the PR is not merged with current `main`). **Tested** - AMD Radeon RX 7800 XT (RDNA3, driver 32.0.31035.1003), Ryzen 7 5700X3D, 64 GB, Windows 11 25H2 (26200), Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, DXC 1.8.2502.11 (Windows Kit 10.0.26100.0). `XCL_ADAPTER` unset, so the physical GPU was used, not WARP. Own target dir, rebuilt from scratch for this head. - `cargo build --workspace -j 4`: ok. - `cargo test --workspace -j 4 --no-fail-fast -- --test-threads=4 --nocapture` (debug): **777 passed, 0 failed, 41 ignored** over 20 test binaries. One `SKIPPED` line: `heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows`. The new `hle::dstorage::tests::uncompressed_request_with_short_source_is_zero_padded` passes. At this head the tree has no `fuzz_tests`, so the known AMD fuzz failure (#2115) does not come up. - 60 s smoke (`scripts/smoke.ps1` of each commit, release builds, title run from a local copy): base `9e3831e` twice, then this head, in the order base, PR, base: | run | frames shown | peak commit | removals / crashes | |---|---|---|---| | base `9e3831e`, run 1 | 1458 | 17520 MB | 0 / 0 | | this head `58fa588` | 1464 | 18086 MB | 0 / 0 | | base `9e3831e`, run 2 | 1456 | 16579 MB | 0 / 0 | ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: AMD Radeon RX 7800 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1456 (PresentX 1456) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16579 MB ``` ``` xcl-smoke v1 commit: 58fa588e247dd34f70a2edb5c35c8a08aee47679 gpu: AMD Radeon RX 7800 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1464 (PresentX 1464) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18086 MB ``` The older `smoke.ps1` at these commits prints the folder name as `title:`; I replaced it with `retail-title` in the blocks above and changed nothing else. Peak commit varies by about 1.5 GB between runs of the same commit here (base: 17520 and 16579 MB), so the 18086 MB of this head is within that spread, not a measured increase. **Not tested** - The merge with current `main` (`8b957bec`): the suite and the smoke ran on this head and its merge base only. - A title read that is shorter than its request (the case the PR fixes): the 60 s smoke does not show that path being hit. - NVIDIA, Intel, Linux/Wine, AMD RDNA2/RDNA4. **AI use:** Claude Code (Claude Sonnet 5.5) ran the tests and drafted this report.
Foniass commented 2026-12-01 06:19:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:19:26Z.


Triage (#1607) – head 58fa588

Titles cannot reach the case this pads. queue_enqueue_request runs Request::check first. For an uncompressed request ((false, 0)), check returns E_DESTINATION_SIZE whenever destination_size != source_size. This was already in this PR's base and is still on main. So a short uncompressed request is refused at enqueue and never reaches execute.
The new test calls execute directly and skips that check. Zero-padding would also contradict the refusal the GDK documents for this request.
Recommendation: close (bad: pads requests that EnqueueRequest already refuses; no change for titles).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302741224 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1625#issuecomment-7302741224). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:19:26Z. --- **Triage (#1607)** – head 58fa588 Titles cannot reach the case this pads. `queue_enqueue_request` runs `Request::check` first. For an uncompressed request (`(false, 0)`), `check` returns `E_DESTINATION_SIZE` whenever `destination_size != source_size`. This was already in this PR's base and is still on main. So a short uncompressed request is refused at enqueue and never reaches `execute`. The new test calls `execute` directly and skips that check. Zero-padding would also contradict the refusal the GDK documents for this request. Recommendation: close (bad: pads requests that EnqueueRequest already refuses; no change for titles). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1625:upstream-pr/1625'
git switch 'upstream-pr/1625'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1625'
git switch 'upstream-pr/1625'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1625'
git switch 'upstream-pr/1625'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1625'
git switch 'main'
git merge --squash 'upstream-pr/1625'
git switch 'main'
git merge --ff-only 'upstream-pr/1625'
git switch 'main'
git merge 'upstream-pr/1625'
git push origin 'main'
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
xcl-dev/xcl!1615
No description provided.