replay: --dump checks the shader a capture names, and its length #602

Open
qnjk wants to merge 1 commit from qnjk/Darner:replay-dump-bounds into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: dump (crates/darner-gpu/src/replay/play.rs:377) walks a capture's pipelines and writes each shader blob out, indexing the capture's code table with an id read from the same file and allocating the length it finds there:

    let c = &frame.codes[*blob as usize];        // :389
    let mut bytes = vec![0; c.len as usize];     // :390
    

    A capture is untrusted input — darner replay --dump reads whatever file the user points at — so a bad id is an out-of-bounds panic and a bad length is a multi-terabyte allocation. Neither says what was wrong; the command aborts.

  • This change checks the id against frame.codes.len() and the length against the capture file's own size, and answers with the error the command already uses for an unreadable capture, naming the pipeline, the id and the length. Both new error paths are tested with synthetic captures.

How it was tested

  • Tested revision: f071e51 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-gpu --features diagnostics --lib -- replay — passes, with the new tests among them.
    • cargo clippy --locked -p darner-gpu --all-targets -- -D warnings passes.
    • Fail-before, with the fix reverted to the two old lines and the tests kept:
      a_capture_that_names_no_shader_is_refused ... FAILED
      panicked at crates\darner-gpu\src\replay\play.rs:390: index out of bounds: the len is 0 but the index is 3
      
      and, for the length:
      a_shader_longer_than_shaders_bin_is_refused_before_it_is_allocated ... FAILED
      memory allocation of 1125899906842624 bytes failed
      
      (1 PiB — the process dies before the test can assert anything).
  • Changes a default: no. A capture whose ids and lengths are consistent is dumped exactly as before.
  • A/B result: not applicable — no default changes and no speed claim.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not run to completion here; the pre-existing darner-gpu test deadlock (#224) and darner-shader waterfall fixture failure (#227) make the whole-workspace run non-green on this machine. The crate's replay tests pass.
  • Gameplay, when relevant: not applicable — this is the offline replay tool.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: only the shader-blob path is bounded; the other dump parts (roots, constants) and compare read their own recorded lengths and were not reviewed in this change.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: darner replay --dump is an offline tool; the evidence is the two tests, which abort the test process on main.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: 576 files ok).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #45 and #46 change crates/darner-gpu/src/replay/play.rs; neither mentions dump or the shader table. No open or closed issue mentions the replay dump.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `dump` (`crates/darner-gpu/src/replay/play.rs:377`) walks a capture's pipelines and writes each shader blob out, indexing the capture's code table with an id read from the same file and allocating the length it finds there: ```rust let c = &frame.codes[*blob as usize]; // :389 let mut bytes = vec![0; c.len as usize]; // :390 ``` A capture is untrusted input — `darner replay --dump` reads whatever file the user points at — so a bad id is an out-of-bounds panic and a bad length is a multi-terabyte allocation. Neither says what was wrong; the command aborts. - This change checks the id against `frame.codes.len()` and the length against the capture file's own size, and answers with the error the command already uses for an unreadable capture, naming the pipeline, the id and the length. Both new error paths are tested with synthetic captures. ## How it was tested - Tested revision: `f071e51` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-gpu --features diagnostics --lib -- replay` — passes, with the new tests among them. - `cargo clippy --locked -p darner-gpu --all-targets -- -D warnings` passes. - Fail-before, with the fix reverted to the two old lines and the tests kept: ``` a_capture_that_names_no_shader_is_refused ... FAILED panicked at crates\darner-gpu\src\replay\play.rs:390: index out of bounds: the len is 0 but the index is 3 ``` and, for the length: ``` a_shader_longer_than_shaders_bin_is_refused_before_it_is_allocated ... FAILED memory allocation of 1125899906842624 bytes failed ``` (1 PiB — the process dies before the test can assert anything). - Changes a default: no. A capture whose ids and lengths are consistent is dumped exactly as before. - A/B result: not applicable — no default changes and no speed claim. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not run to completion here; the pre-existing `darner-gpu` test deadlock (#224) and `darner-shader` waterfall fixture failure (#227) make the whole-workspace run non-green on this machine. The crate's `replay` tests pass. - Gameplay, when relevant: not applicable — this is the offline replay tool. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: only the shader-blob path is bounded; the other `dump` parts (roots, constants) and `compare` read their own recorded lengths and were not reviewed in this change. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: `darner replay --dump` is an offline tool; the evidence is the two tests, which abort the test process on `main`. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: 576 files ok). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #45 and #46 change `crates/darner-gpu/src/replay/play.rs`; neither mentions `dump` or the shader table. No open or closed issue mentions the replay dump. - Replaces or overlaps: none found
`dump` indexed the capture's code table with the blob id a pipeline part
records (`frame.codes[*blob as usize]`) and allocated the `len` bytes it found
there before `read_at` had checked anything against `shaders.bin`. Both
numbers are the capture's own, and a capture is opened as a file someone else
may have written: the recorder itself writes `u32::MAX` as the blob when the
shader could not be written (`record.rs`), and a `frame.bin` that was
bit-flipped can name any blob and any `len` (a truncated `shaders.bin` was
refused by `read_at`, but a wrong `len` was allocated first). `make_pipelines`
already refuses such a capture with `frame.codes.get`; `--dump` panicked on the
index, or aborted on the allocation.

The blob is looked up with `.get`, and `at .. at + len` is checked against
`shaders.bin`'s own size before the vec is made, so the command answers with
its usual `Err` for a capture that disagrees with itself.
`a_capture_that_names_no_shader_is_refused` and
`a_shader_longer_than_shaders_bin_is_refused_before_it_is_allocated` pin both;
before this change the first panicked with "index out of bounds: the len is 0
but the index is 3" and the second aborted with "memory allocation of
1125899906842624 bytes failed".
TrustNo1 changed title from [pr-fix] replay: --dump checks the shader a capture names, and its length to replay: --dump checks the shader a capture names, and its length 2026-12-06 03:26:27 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'replay-dump-bounds:qnjk-replay-dump-bounds'
git switch 'qnjk-replay-dump-bounds'

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 'qnjk-replay-dump-bounds'
git switch 'qnjk-replay-dump-bounds'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-replay-dump-bounds'
git switch 'qnjk-replay-dump-bounds'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-replay-dump-bounds'
git switch 'Main'
git merge --squash 'qnjk-replay-dump-bounds'
git switch 'Main'
git merge --ff-only 'qnjk-replay-dump-bounds'
git switch 'Main'
git merge 'qnjk-replay-dump-bounds'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!602
No description provided.