Check pipeline stream subobject bounds #1524

Manually merged
github merged 2 commits from github-bot/gh-1524 into main 2026-11-29 08:21:55 +00:00 AGit
Owner

@⁠Gauss999 on GitHub · 2026-11-28 21:14 UTC · original
Gauss999:patch-2 → main · +93 −5 · 1 files · 2 commits · merged 2026-11-29 08:16 UTC

Summary

  • Validate each pipeline stream subobject's payload and aligned advance with checked arithmetic.
  • Report truncated subobjects through keep.lost and stop before reading outside SizeInBytes.
  • Keep valid subobject decoding unchanged.

Tests

  • Added a regression for a stream ending after a subobject kind, before its payload.
  • Added bounds regressions for truncation and overflow in payload offsets, payload ends, and aligned advances.
  • Existing valid-stream regression remains unchanged.

No local build or tests were run. CI depends on maintainer approval; no CI results are available yet.

**@⁠Gauss999** on GitHub · 2026-11-28 21:14 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1524) `Gauss999:patch-2` → `main` · +93 −5 · 1 files · 2 commits · merged 2026-11-29 08:16 UTC ## Summary - Validate each pipeline stream subobject's payload and aligned advance with checked arithmetic. - Report truncated subobjects through `keep.lost` and stop before reading outside `SizeInBytes`. - Keep valid subobject decoding unchanged. ## Tests - Added a regression for a stream ending after a subobject kind, before its payload. - Added bounds regressions for truncation and overflow in payload offsets, payload ends, and aligned advances. - Existing valid-stream regression remains unchanged. No local build or tests were run. CI depends on maintainer approval; no CI results are available yet.
Reject truncated payloads and aligned advances without reading past SizeInBytes.

Add truncation and overflow regressions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 21:19:11 +00:00
Author
Owner

@⁠babuakhil on GitHub · 2026-11-28 22:09 UTC · original

Built and ran this on Windows, since it hadn't been run yet: Windows 11, Rust 1.98.1 (pinned), applied on current main (d4b5d51); cherry-picks cleanly. Clippy reports nothing in pso.rs.

Heads-up for CI: replay is #[cfg(all(windows, feature = "diagnostics"))], so these tests only build with --features diagnostics. CI's cargo test --workspace --locked runs without it and won't run them. With the feature, all three replay::pso tests pass.

The out-of-bounds read is real and fixed. I fed stream a few hand-made streams from a throwaway test (not part of this PR):

Stream main this PR
kind 9, SizeInBytes = 4 (payload past the end) reads the payload from outside the stream (5) lost, nothing read
kind 17 (DXGI_SAMPLE_DESC), SizeInBytes = 16 read read
kind 17, SizeInBytes = 12 (complete, no trailing padding) read lost
kind 9 then kind 17, SizeInBytes = 20 (last one complete, unpadded) both read kind 17 lost

One problem: the last two rows. subobject_bounds requires the aligned end (next) to fit, so a last subobject whose payload ends on a 4-byte boundary (DXGI_SAMPLE_DESC; D3D12_BLEND_DESC and DEPTH_STENCIL_DESC1 end the same way) is dropped when SizeInBytes doesn't include the trailing pad, although every byte read is inside the stream. Streams built from d3dx12-style alignas(void*) subobjects are padded, so this may never happen with the title's streams, but it is a change from main beyond the bounds fix.

Checking the payload's end and using next only to advance keeps the fix and accepts those:

let next = end.checked_add(7)? & !7;
(end <= stream_size).then_some((value, next))

The loop's at + 4 <= SizeInBytes check already ends the walk when next runs past the end. subobject_bounds(0, 4, 4, 7) stays None (the payload ends at 8), and the overflow cases still return None from the checked_adds.

**@⁠babuakhil** on GitHub · 2026-11-28 22:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1524#issuecomment-7246539384) Built and ran this on Windows, since it hadn't been run yet: Windows 11, Rust 1.98.1 (pinned), applied on current `main` (`d4b5d51`); cherry-picks cleanly. Clippy reports nothing in `pso.rs`. **Heads-up for CI:** `replay` is `#[cfg(all(windows, feature = "diagnostics"))]`, so these tests only build with `--features diagnostics`. CI's `cargo test --workspace --locked` runs without it and won't run them. With the feature, all three `replay::pso` tests pass. **The out-of-bounds read is real and fixed.** I fed `stream` a few hand-made streams from a throwaway test (not part of this PR): | Stream | `main` | this PR | |---|---|---| | kind 9, `SizeInBytes = 4` (payload past the end) | reads the payload from outside the stream (`5`) | lost, nothing read | | kind 17 (`DXGI_SAMPLE_DESC`), `SizeInBytes = 16` | read | read | | kind 17, `SizeInBytes = 12` (complete, no trailing padding) | read | **lost** | | kind 9 then kind 17, `SizeInBytes = 20` (last one complete, unpadded) | both read | **kind 17 lost** | **One problem:** the last two rows. `subobject_bounds` requires the *aligned* end (`next`) to fit, so a last subobject whose payload ends on a 4-byte boundary (`DXGI_SAMPLE_DESC`; `D3D12_BLEND_DESC` and `DEPTH_STENCIL_DESC1` end the same way) is dropped when `SizeInBytes` doesn't include the trailing pad, although every byte read is inside the stream. Streams built from d3dx12-style `alignas(void*)` subobjects are padded, so this may never happen with the title's streams, but it is a change from `main` beyond the bounds fix. Checking the payload's end and using `next` only to advance keeps the fix and accepts those: ```rust let next = end.checked_add(7)? & !7; (end <= stream_size).then_some((value, next)) ``` The loop's `at + 4 <= SizeInBytes` check already ends the walk when `next` runs past the end. `subobject_bounds(0, 4, 4, 7)` stays `None` (the payload ends at 8), and the overflow cases still return `None` from the `checked_add`s.
Validate only the payload end against SizeInBytes while keeping checked aligned advancement. Add decoding and bounds regressions for complete unpadded final subobjects, truncation, and overflow.
Author
Owner

@⁠Gauss999 on GitHub · 2026-11-28 22:45 UTC · original

Thanks @⁠babuakhil for validating this on Windows and catching the unpadded-final-subobject regression.

subobject_bounds now computes value and end with checked arithmetic and checks only end <= stream_size. The aligned next calculation also remains checked, but next may extend past the stream and is used only for advancement; the existing loop condition ends the walk before another read.

I added a decoding regression for a final kind 17 / DXGI_SAMPLE_DESC with SizeInBytes = 12: its complete 8-byte payload is accepted without trailing padding and decoded with no loss reported. The bounds regression also checks (value, next) == (4, 16) for that case, while the truncated-payload case and all payload/alignment overflow cases still return None.

I reviewed the resulting diff; only crates/victory-gpu/src/replay/pso.rs changed. I have not run the Windows-only tests locally.

**@⁠Gauss999** on GitHub · 2026-11-28 22:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1524#issuecomment-7246957147) Thanks @⁠babuakhil for validating this on Windows and catching the unpadded-final-subobject regression. `subobject_bounds` now computes `value` and `end` with checked arithmetic and checks only `end <= stream_size`. The aligned `next` calculation also remains checked, but `next` may extend past the stream and is used only for advancement; the existing loop condition ends the walk before another read. I added a decoding regression for a final kind 17 / `DXGI_SAMPLE_DESC` with `SizeInBytes = 12`: its complete 8-byte payload is accepted without trailing padding and decoded with no loss reported. The bounds regression also checks `(value, next) == (4, 16)` for that case, while the truncated-payload case and all payload/alignment overflow cases still return `None`. I reviewed the resulting diff; only `crates/victory-gpu/src/replay/pso.rs` changed. I have not run the Windows-only tests locally.
Author
Owner

@⁠babuakhil on GitHub · 2026-11-28 23:04 UTC · original

Re-checked with b53b952 on d4b5d51 (Windows 11, Rust 1.98.1): builds, clippy (--all-features) reports nothing in pso.rs, and with --features diagnostics all four replay::pso tests pass, a_complete_unpadded_final_subobject_is_taken among them (27/27 replay tests).

The same throwaway streams as before now give:

Stream before (fad0e0b) now
kind 9, SizeInBytes = 4 lost lost
kind 17, SizeInBytes = 16 read read
kind 17, SizeInBytes = 12 lost read, no loss
kind 9 then kind 17, SizeInBytes = 20 kind 17 lost both read, no loss

So the out-of-bounds read stays fixed, and the unpadded final subobjects are taken again. Looks good to me.

**@⁠babuakhil** on GitHub · 2026-11-28 23:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1524#issuecomment-7247175004) Re-checked with `b53b952` on `d4b5d51` (Windows 11, Rust 1.98.1): builds, clippy (`--all-features`) reports nothing in `pso.rs`, and with `--features diagnostics` all four `replay::pso` tests pass, `a_complete_unpadded_final_subobject_is_taken` among them (27/27 `replay` tests). The same throwaway streams as before now give: | Stream | before (`fad0e0b`) | now | |---|---|---| | kind 9, `SizeInBytes = 4` | lost | lost | | kind 17, `SizeInBytes = 16` | read | read | | kind 17, `SizeInBytes = 12` | lost | **read**, no loss | | kind 9 then kind 17, `SizeInBytes = 20` | kind 17 lost | **both read**, no loss | So the out-of-bounds read stays fixed, and the unpadded final subobjects are taken again. Looks good to me.
github manually merged commit 0c1e105641 into main 2026-11-29 08:21:55 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!1524
No description provided.