Shader dxbc: use checked arithmetic for bounds slicing #3380

Open
github-bot wants to merge 1 commit from github-bot/gh-3380 into main AGit
Owner

@⁠Arkenoz on GitHub · 2026-11-26 21:04 UTC · original
Arkenoz:fix/dxbc-checked-arithmetic → main · +65 −6 · 1 files · 1 commits · open

Tracked in #1633.

Problem

  1. u16_at, u32_at, and u64_at in crates/victory-shader/src/dxbc.rs computed at + 2, at + 4, and at + 8 with unchecked addition, panicking on overflow when at is near usize::MAX instead of returning Err(ShaderError::Malformed("truncated")).
  2. Container::parse computed offset + 4, offset + 8, and offset + 8 + size with unchecked addition.

Changes

  • Updated u16_at, u32_at, and u64_at to use checked_add, returning Err(ShaderError::Malformed("truncated")) on overflow or out-of-bounds.
  • Updated Container::parse to use checked_add for part header and body bounds, returning ShaderError::Malformed("part header out of bounds") / ShaderError::Malformed("part data out of bounds").
  • Added unit tests (helpers_overflow_safely, parse_rejects_max_offset_and_size) covering near-max offsets and u32::MAX part offsets/sizes.

Verification

  • cargo test -p victory-shader dxbc (4 passed)
  • cargo clippy -p victory-shader --all-targets (0 warnings)

AI-assisted with Gemini.

**@⁠Arkenoz** on GitHub · 2026-11-26 21:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/3380) `Arkenoz:fix/dxbc-checked-arithmetic` → `main` · +65 −6 · 1 files · 1 commits · open Tracked in #1633. ### Problem 1. `u16_at`, `u32_at`, and `u64_at` in `crates/victory-shader/src/dxbc.rs` computed `at + 2`, `at + 4`, and `at + 8` with unchecked addition, panicking on overflow when `at` is near `usize::MAX` instead of returning `Err(ShaderError::Malformed("truncated"))`. 2. `Container::parse` computed `offset + 4`, `offset + 8`, and `offset + 8 + size` with unchecked addition. ### Changes - Updated `u16_at`, `u32_at`, and `u64_at` to use `checked_add`, returning `Err(ShaderError::Malformed("truncated"))` on overflow or out-of-bounds. - Updated `Container::parse` to use `checked_add` for part header and body bounds, returning `ShaderError::Malformed("part header out of bounds")` / `ShaderError::Malformed("part data out of bounds")`. - Added unit tests (`helpers_overflow_safely`, `parse_rejects_max_offset_and_size`) covering near-max offsets and `u32::MAX` part offsets/sizes. ### Verification - `cargo test -p victory-shader dxbc` (4 passed) - `cargo clippy -p victory-shader --all-targets` (0 warnings) AI-assisted with Gemini.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:13:41 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 21:07 UTC · original · approved these changes

LGTM — verified on Windows against origin/main (63bcca4).

  • Using checked_add for part header/body bounds in Container::parse and in u16_at/u32_at/u64_at cleanly eliminates arithmetic overflow panics on malformed DXBC containers.
  • cargo test -p victory-shader --lib dxbc:: -- --test-threads=1: 4 passed, 0 failed (including helpers_overflow_safely and parse_rejects_max_offset_and_size).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 21:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3380#pullrequestreview-6080485336) · **approved these changes** LGTM — verified on Windows against `origin/main` (`63bcca4`). - Using `checked_add` for part header/body bounds in `Container::parse` and in `u16_at`/`u32_at`/`u64_at` cleanly eliminates arithmetic overflow panics on malformed DXBC containers. - `cargo test -p victory-shader --lib dxbc:: -- --test-threads=1`: 4 passed, 0 failed (including `helpers_overflow_safely` and `parse_rejects_max_offset_and_size`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Arkenoz on GitHub · 2026-11-26 21:10 UTC · original

The CI failure is an unrelated flaky test in victory-gpu (descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait). Could someone re-run the check?

LGTM — verified on Windows against origin/main (63bcca4).

* Using `checked_add` for part header/body bounds in `Container::parse` and in `u16_at`/`u32_at`/`u64_at` cleanly eliminates arithmetic overflow panics on malformed DXBC containers.

* `cargo test -p victory-shader --lib dxbc:: -- --test-threads=1`: 4 passed, 0 failed (including `helpers_overflow_safely` and `parse_rejects_max_offset_and_size`).

* `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean.

* `cargo xtask policy`: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Arkenoz** on GitHub · 2026-11-26 21:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/3380#issuecomment-7203461955) The CI failure is an unrelated flaky test in `victory-gpu` (`descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait`). Could someone re-run the check? > LGTM — verified on Windows against `origin/main` (`63bcca4`). > > * Using `checked_add` for part header/body bounds in `Container::parse` and in `u16_at`/`u32_at`/`u64_at` cleanly eliminates arithmetic overflow panics on malformed DXBC containers. > > * `cargo test -p victory-shader --lib dxbc:: -- --test-threads=1`: 4 passed, 0 failed (including `helpers_overflow_safely` and `parse_rejects_max_offset_and_size`). > > * `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. > > * `cargo xtask policy`: 191 files ok. > > > Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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 origin '+refs/pull/3380/head:github-bot/gh-3380'
git switch 'github-bot/gh-3380'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3380'
git switch 'github-bot/gh-3380'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3380'
git switch 'github-bot/gh-3380'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3380'
git switch 'main'
git merge --squash 'github-bot/gh-3380'
git switch 'main'
git merge --ff-only 'github-bot/gh-3380'
git switch 'main'
git merge 'github-bot/gh-3380'
git push origin 'main'
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/Marvisak--VIctory!3380
No description provided.