DXBC parser accepts part offsets inside the header or part table #777

Open
opened 2026-11-26 04:13:57 +00:00 by github-bot · 7 comments
Owner

@⁠gustavocosta2 on GitHub · 2026-11-24 10:30 UTC · original

The DXBC parser can return a successful result when a part points into the container header or the part table. In a synthetic case, a part with offset 0 is read back with the container magic DXBC as its FourCC.

I prepared a patch that checks that the part table fits inside the declared container size and rejects parts that start before the end of that table.

The regression test failed with the original parser and passed with the fix on Apple Silicon macOS using Rust 1.98.1. The full cargo test -p victory-shader --locked --lib run passed 97 tests, with one benchmark ignored.

GitHub rejected PR creation from my account, so I'm sharing the patch here for review.

**@⁠gustavocosta2** on GitHub · 2026-11-24 10:30 UTC · [original](https://github.com/Marvisak/VIctory/issues/777) The DXBC parser can return a successful result when a part points into the container header or the part table. In a synthetic case, a part with offset 0 is read back with the container magic `DXBC` as its FourCC. I prepared a patch that checks that the part table fits inside the declared container size and rejects parts that start before the end of that table. - [Patch commit](https://github.com/gustavocosta2/VIctory/commit/fe8b10f) - [Branch](https://github.com/gustavocosta2/VIctory/tree/fix/dxbc-part-table) The regression test failed with the original parser and passed with the fix on Apple Silicon macOS using Rust 1.98.1. The full `cargo test -p victory-shader --locked --lib` run passed 97 tests, with one benchmark ignored. GitHub rejected PR creation from my account, so I'm sharing the patch here for review.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:57 +00:00
Author
Owner

@⁠sebastianspicker on GitHub · 2026-11-24 11:02 UTC · original

This looks covered by PR #326 already. Its dxbc::tests::rejects_parts_inside_the_header sets the first part offset to 0, 0x10 and just inside the offset table, and expects "part overlaps the container header". That's the same synthetic case as here, where DXBC is read back as a part's FourCC. At #326's current head bf594d5, all 28 dxbc:: tests pass on macOS with Rust 1.98.1.

So if #326 lands, this can probably be closed as a duplicate. If #326 stalls, your patch is the smaller change.

AI-assisted.

**@⁠sebastianspicker** on GitHub · 2026-11-24 11:02 UTC · [original](https://github.com/Marvisak/VIctory/issues/777#issuecomment-7129567760) This looks covered by PR #326 already. Its `dxbc::tests::rejects_parts_inside_the_header` sets the first part offset to 0, 0x10 and just inside the offset table, and expects "part overlaps the container header". That's the same synthetic case as here, where `DXBC` is read back as a part's FourCC. At #326's current head `bf594d5`, all 28 `dxbc::` tests pass on macOS with Rust 1.98.1. So if #326 lands, this can probably be closed as a duplicate. If #326 stalls, your patch is the smaller change. AI-assisted.
Author
Owner

@⁠davutsimsekk on GitHub · 2026-11-24 11:34 UTC · original

The branch is still ready: https://github.com/davutsimsekk/VIctory/tree/fix/dxbc-part-table-bounds (6c65a50, one file, crates/victory-shader/src/dxbc.rs).

As noted above, #326's rejects_parts_inside_the_header covers the same offset-0 case with Malformed("part overlaps the container header"). If #326 lands, this can close; if it stalls, this branch is the smaller fallback: the part table must fit in the declared size, every part offset must follow the table, and two tests cover those bounds. No other files or behaviour change.

Verification on Windows 11, Rust 1.98.1 (MSVC):

  • cargo test -p victory-shader --lib dxbc: 4 passed
  • cargo test -p victory-shader --lib: 122 passed, 1 ignored
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean
  • rustfmt --edition 2024 --check crates/victory-shader/src/dxbc.rs: clean

PR creation is still limited to collaborators, so the branch is here for review or cherry-pick.

**@⁠davutsimsekk** on GitHub · 2026-11-24 11:34 UTC · [original](https://github.com/Marvisak/VIctory/issues/777#issuecomment-7130269464) The branch is still ready: https://github.com/davutsimsekk/VIctory/tree/fix/dxbc-part-table-bounds (`6c65a50`, one file, `crates/victory-shader/src/dxbc.rs`). As noted above, #326's `rejects_parts_inside_the_header` covers the same offset-0 case with `Malformed("part overlaps the container header")`. If #326 lands, this can close; if it stalls, this branch is the smaller fallback: the part table must fit in the declared size, every part offset must follow the table, and two tests cover those bounds. No other files or behaviour change. Verification on Windows 11, Rust 1.98.1 (MSVC): - `cargo test -p victory-shader --lib dxbc`: 4 passed - `cargo test -p victory-shader --lib`: 122 passed, 1 ignored - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean - `rustfmt --edition 2024 --check crates/victory-shader/src/dxbc.rs`: clean PR creation is still limited to collaborators, so the branch is here for review or cherry-pick.
Author
Owner

@⁠Gruzzberry on GitHub · 2026-11-24 11:37 UTC · original

Read through fe8b10f against Container::parse on ffe310e; I did not build or run the branch, so this is a review of the diff only.

  • The new table_end check and the per-part offset < table_end check cover the case in the report: offset 0 reads the container magic as a FourCC, and an offset inside the table reads another entry's bytes as one. HEADER_SIZE + 4 * count cannot overflow, as count is bounded by MAX_PARTS just above it.
  • The new test sets both offsets (0 and the table entry itself). An offset that lands exactly on table_end stays accepted, which matches the layout (the first part begins right after the table).

Possibly relevant to who takes this: #343 (Shaders: reject overlapping DXBC container parts) and #326 (DXBC/DXIL parser and sampler/SP3 robustness fixes) are open and also touch Container::parse's offset checks, so the three may conflict or overlap.

AI use: written with Claude from reading the diff; nothing was run.

**@⁠Gruzzberry** on GitHub · 2026-11-24 11:37 UTC · [original](https://github.com/Marvisak/VIctory/issues/777#issuecomment-7130346221) Read through `fe8b10f` against `Container::parse` on `ffe310e`; I did not build or run the branch, so this is a review of the diff only. - The new `table_end` check and the per-part `offset < table_end` check cover the case in the report: offset 0 reads the container magic as a FourCC, and an offset inside the table reads another entry's bytes as one. `HEADER_SIZE + 4 * count` cannot overflow, as `count` is bounded by `MAX_PARTS` just above it. - The new test sets both offsets (0 and the table entry itself). An offset that lands exactly on `table_end` stays accepted, which matches the layout (the first part begins right after the table). Possibly relevant to who takes this: #343 (`Shaders: reject overlapping DXBC container parts`) and #326 (`DXBC/DXIL parser and sampler/SP3 robustness fixes`) are open and also touch `Container::parse`'s offset checks, so the three may conflict or overlap. _AI use: written with Claude from reading the diff; nothing was run._
Author
Owner

@⁠studiostephe on GitHub · 2026-11-24 12:09 UTC · original

Second implementation of this fix for review — same invariant as @⁠gustavocosta2's patch, plus a check that the part table itself fits the declared container size.

Patch (one commit on main ffe310e)

diff --git a/crates/victory-shader/src/dxbc.rs b/crates/victory-shader/src/dxbc.rs
index 7a20963..54a61ad 100644
--- a/crates/victory-shader/src/dxbc.rs
+++ b/crates/victory-shader/src/dxbc.rs
@@ -80,9 +80,18 @@ impl<'a> Container<'a> {
         if count > MAX_PARTS {
             return Err(ShaderError::Malformed("implausible part count"));
         }
+        let table_end = HEADER_SIZE + 4 * count;
+        if table_end > data.len() {
+            return Err(ShaderError::Malformed("part table out of bounds"));
+        }
         let mut parts = Vec::with_capacity(count);
         for i in 0..count {
             let offset = u32_at(data, HEADER_SIZE + 4 * i)? as usize;
+            if offset < table_end {
+                return Err(ShaderError::Malformed(
+                    "part starts inside the header or part table",
+                ));
+            }
             let fourcc = FourCC(
                 data.get(offset..offset + 4)
                     .ok_or(ShaderError::Malformed("part header out of bounds"))?
@@ -178,4 +187,29 @@ mod tests {
         bytes.truncate(last);
         assert!(Container::parse(&bytes).is_err());
     }
+
+    #[test]
+    fn rejects_parts_starting_inside_the_header_or_table() {
+        let mut bytes = build(&[(FourCC([0; 4]), &[]), (FourCC::HASH, &[])]);
+        let second_entry = HEADER_SIZE + 4;
+        // A zero digest and a zero first FourCC make both bogus sizes zero,
+        // so a part at any offset in the header reads back as "valid".
+        for offset in [0u32, second_entry as u32] {
+            bytes[second_entry..second_entry + 4].copy_from_slice(&offset.to_le_bytes());
+            assert_eq!(
+                Container::parse(&bytes).unwrap_err(),
+                ShaderError::Malformed("part starts inside the header or part table"),
+            );
+        }
+    }
+
+    #[test]
+    fn rejects_a_part_table_longer_than_the_container() {
+        let mut bytes = build(&[(FourCC::SFI0, &[1, 2, 3, 4])]);
+        bytes[0x1C..0x20].copy_from_slice(&7u32.to_le_bytes());
+        assert_eq!(
+            Container::parse(&bytes).unwrap_err(),
+            ShaderError::Malformed("part table out of bounds"),
+        );
+    }
 }

Verified

Rust 1.98.1 (the repo's pinned toolchain) on macOS aarch64:

  • cargo test -p victory-shader --lib --locked: 98 passed, 0 failed, 1 ignored (baseline on clean ffe310e is 97 passed — the new tests are dxbc::tests::rejects_parts_starting_inside_the_header_or_table and dxbc::tests::rejects_a_part_table_longer_than_the_container; both fail on the unpatched parser: offset 0 and offset 0x24 (mid-table) parse "successfully" today, with the container magic read back as a FourCC)
  • rustfmt --edition 2024 --check on the changed file: clean
  • cargo clippy -p victory-shader --all-targets --locked: no new warnings (the two unused import warnings in the crate's test target exist identically on clean ffe310e)

The parser is platform-neutral, so the macOS run exercises the same code CI's cargo test --workspace --locked will.

AI use: found by reading the code at ffe310e; written and verified by qwen3.8_27b running locally on an M1 Mac. No game data used.

**@⁠studiostephe** on GitHub · 2026-11-24 12:09 UTC · [original](https://github.com/Marvisak/VIctory/issues/777#issuecomment-7131050754) Second implementation of this fix for review — same invariant as @⁠gustavocosta2's patch, plus a check that the part table itself fits the declared container size. ## Patch (one commit on `main` `ffe310e`) ```diff diff --git a/crates/victory-shader/src/dxbc.rs b/crates/victory-shader/src/dxbc.rs index 7a20963..54a61ad 100644 --- a/crates/victory-shader/src/dxbc.rs +++ b/crates/victory-shader/src/dxbc.rs @@ -80,9 +80,18 @@ impl<'a> Container<'a> { if count > MAX_PARTS { return Err(ShaderError::Malformed("implausible part count")); } + let table_end = HEADER_SIZE + 4 * count; + if table_end > data.len() { + return Err(ShaderError::Malformed("part table out of bounds")); + } let mut parts = Vec::with_capacity(count); for i in 0..count { let offset = u32_at(data, HEADER_SIZE + 4 * i)? as usize; + if offset < table_end { + return Err(ShaderError::Malformed( + "part starts inside the header or part table", + )); + } let fourcc = FourCC( data.get(offset..offset + 4) .ok_or(ShaderError::Malformed("part header out of bounds"))? @@ -178,4 +187,29 @@ mod tests { bytes.truncate(last); assert!(Container::parse(&bytes).is_err()); } + + #[test] + fn rejects_parts_starting_inside_the_header_or_table() { + let mut bytes = build(&[(FourCC([0; 4]), &[]), (FourCC::HASH, &[])]); + let second_entry = HEADER_SIZE + 4; + // A zero digest and a zero first FourCC make both bogus sizes zero, + // so a part at any offset in the header reads back as "valid". + for offset in [0u32, second_entry as u32] { + bytes[second_entry..second_entry + 4].copy_from_slice(&offset.to_le_bytes()); + assert_eq!( + Container::parse(&bytes).unwrap_err(), + ShaderError::Malformed("part starts inside the header or part table"), + ); + } + } + + #[test] + fn rejects_a_part_table_longer_than_the_container() { + let mut bytes = build(&[(FourCC::SFI0, &[1, 2, 3, 4])]); + bytes[0x1C..0x20].copy_from_slice(&7u32.to_le_bytes()); + assert_eq!( + Container::parse(&bytes).unwrap_err(), + ShaderError::Malformed("part table out of bounds"), + ); + } } ``` ## Verified Rust `1.98.1` (the repo's pinned toolchain) on macOS aarch64: - `cargo test -p victory-shader --lib --locked`: **98 passed, 0 failed, 1 ignored** (baseline on clean `ffe310e` is 97 passed — the new tests are `dxbc::tests::rejects_parts_starting_inside_the_header_or_table` and `dxbc::tests::rejects_a_part_table_longer_than_the_container`; both fail on the unpatched parser: offset 0 and offset `0x24` (mid-table) parse "successfully" today, with the container magic read back as a FourCC) - `rustfmt --edition 2024 --check` on the changed file: clean - `cargo clippy -p victory-shader --all-targets --locked`: no new warnings (the two `unused import` warnings in the crate's test target exist identically on clean `ffe310e`) The parser is platform-neutral, so the macOS run exercises the same code CI's `cargo test --workspace --locked` will. _AI use: found by reading the code at `ffe310e`; written and verified by qwen3.8_27b running locally on an M1 Mac. No game data used._
Author
Owner

@⁠winne42 on GitHub · 2026-11-24 19:18 UTC · original

I tested the five fixes proposed for this issue side by side. One case, an offset inside the part table, is easy to get wrong in a test, so I ran the same synthetic inputs against every candidate. The probe only checks whether Container::parse returns Ok or Err, not the error text, and it builds its containers by hand rather than with each branch's build() helper.

Setup: native Linux x86_64, Rust 1.98.1, cargo test -p victory-shader --lib --locked. Each candidate had its own worktree and target directory. The parser is platform-neutral.

Candidates:

  • gustavocosta2 fe8b10f
  • davutsimsekk 6c65a50
  • studiostephe's inline patch from the comment above, applied to ffe310e
  • #343 at 9459c12
  • #326 at c8d7283

Results

Case main gustavo davut studiostephe #343 #326
A: one part at offset 0 (this issue's repro) Ok Err Err Err Ok Err
B: offset 0x10, inside the digest Ok Err Err Err Ok Err
C2: offset inside the part table, zero first FourCC Ok Err Err Err Err Err
E: offset 0 with a nonzero digest (nonzero bogus size) Ok Err Err Err Ok Err
F, G, H: valid layouts (3 parts, 0 parts, table in reverse order) Ok Ok Ok Ok Ok Ok
I, J, K: count past size, offset u32::MAX, size u32::MAX Err Err Err Err Err Err
L: two table entries with the same offset (outside this issue) Ok Ok Ok Ok Err Err
M: a part nested inside another part (outside this issue) Ok Ok Ok Ok Err Err

Bold marks a result the probe treats as wrong. No input panicked on any candidate.

Other checks

gustavo davut studiostephe #343 #326
Full victory-shader lib suite 97 pass 98 pass 98 pass 59 pass (99 merged onto main) 260 pass
Its new tests fail with main's parse swapped back in 1/1 2/2 2/2 2/3 (the "accepts adjacent" control passes, as it should) 14 of 29 dxbc:: tests
rustfmt dxbc.rs, no new clippy findings yes yes yes yes yes

The only clippy findings on Linux are two unused test imports in emit/mod.rs. They come from main and don't show up in a Windows build.

Notes

  • #343 does not fix this issue. It rejects parts that overlap each other, but a single part at offset 0 overlaps nothing, so it still parses with DXBC as its FourCC. It is complementary to the other fixes, not a replacement. Its branch is also based on d2a4bae. It merges cleanly onto ffe310e and passes there.
  • gustavo, davut and studiostephe make the same fix: a part offset must not be below HEADER_SIZE + 4 * count. They differ only in error text and tests. Their extra "part table past the container size" check doesn't change behaviour: on main that input already fails with Malformed("truncated"). The new tests for it fail on main only because the message differs, so they check the wording, not the bug.
  • Existing tests can mislead. A test that points an offset into the part table usually passes even on main, because the bytes read as the bogus size are large and trip part data out of bounds. gustavo's test (and C2 above) uses a zero first FourCC so that the size is zero and main really accepts the input. That makes it a true regression test.
  • #326 fixes this issue and the overlap cases. It also refuses known FourCCs listed twice and container major versions other than 1. It's a 10-file, +5.5k-line PR, so if it stalls, gustavo's or davut's single-file change is the smaller way to close this.

AI-assisted (Claude Code). Tests were synthetic, with no game files.

**@⁠winne42** on GitHub · 2026-11-24 19:18 UTC · [original](https://github.com/Marvisak/VIctory/issues/777#issuecomment-7141909513) I tested the five fixes proposed for this issue side by side. One case, an offset inside the part table, is easy to get wrong in a test, so I ran the same synthetic inputs against every candidate. The probe only checks whether `Container::parse` returns `Ok` or `Err`, not the error text, and it builds its containers by hand rather than with each branch's `build()` helper. **Setup:** native Linux x86_64, Rust 1.98.1, `cargo test -p victory-shader --lib --locked`. Each candidate had its own worktree and target directory. The parser is platform-neutral. **Candidates:** - gustavocosta2 [`fe8b10f`](https://github.com/gustavocosta2/VIctory/commit/fe8b10f) - davutsimsekk [`6c65a50`](https://github.com/davutsimsekk/VIctory/commit/6c65a50) - studiostephe's inline patch from the comment above, applied to `ffe310e` - #343 at `9459c12` - #326 at `c8d7283` ### Results | Case | `main` | gustavo | davut | studiostephe | #343 | #326 | |---|---|---|---|---|---|---| | A: one part at offset 0 (this issue's repro) | **Ok** | Err | Err | Err | **Ok** | Err | | B: offset 0x10, inside the digest | **Ok** | Err | Err | Err | **Ok** | Err | | C2: offset inside the part table, zero first FourCC | **Ok** | Err | Err | Err | Err | Err | | E: offset 0 with a nonzero digest (nonzero bogus size) | **Ok** | Err | Err | Err | **Ok** | Err | | F, G, H: valid layouts (3 parts, 0 parts, table in reverse order) | Ok | Ok | Ok | Ok | Ok | Ok | | I, J, K: count past size, offset `u32::MAX`, size `u32::MAX` | Err | Err | Err | Err | Err | Err | | L: two table entries with the same offset (outside this issue) | **Ok** | **Ok** | **Ok** | **Ok** | Err | Err | | M: a part nested inside another part (outside this issue) | **Ok** | **Ok** | **Ok** | **Ok** | Err | Err | Bold marks a result the probe treats as wrong. No input panicked on any candidate. ### Other checks | | gustavo | davut | studiostephe | #343 | #326 | |---|---|---|---|---|---| | Full `victory-shader` lib suite | 97 pass | 98 pass | 98 pass | 59 pass (99 merged onto `main`) | 260 pass | | Its new tests fail with `main`'s `parse` swapped back in | 1/1 | 2/2 | 2/2 | 2/3 (the "accepts adjacent" control passes, as it should) | 14 of 29 `dxbc::` tests | | rustfmt `dxbc.rs`, no new clippy findings | yes | yes | yes | yes | yes | The only clippy findings on Linux are two unused test imports in `emit/mod.rs`. They come from `main` and don't show up in a Windows build. ### Notes - **#343 does not fix this issue.** It rejects parts that overlap *each other*, but a single part at offset 0 overlaps nothing, so it still parses with `DXBC` as its FourCC. It is complementary to the other fixes, not a replacement. Its branch is also based on `d2a4bae`. It merges cleanly onto `ffe310e` and passes there. - **gustavo, davut and studiostephe make the same fix:** a part offset must not be below `HEADER_SIZE + 4 * count`. They differ only in error text and tests. Their extra "part table past the container size" check doesn't change behaviour: on `main` that input already fails with `Malformed("truncated")`. The new tests for it fail on `main` only because the message differs, so they check the wording, not the bug. - **Existing tests can mislead.** A test that points an offset into the part table usually passes even on `main`, because the bytes read as the bogus size are large and trip `part data out of bounds`. gustavo's test (and C2 above) uses a zero first FourCC so that the size is zero and `main` really accepts the input. That makes it a true regression test. - **#326** fixes this issue and the overlap cases. It also refuses known FourCCs listed twice and container major versions other than 1. It's a 10-file, +5.5k-line PR, so if it stalls, gustavo's or davut's single-file change is the smaller way to close this. _AI-assisted (Claude Code). Tests were synthetic, with no game files._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:52 UTC · original

Automated triage for the maintainers.

Confirmed on main: Container::parse in crates/victory-shader/src/dxbc.rs reads each part at the offset from the table without checking that it lies past the header and the part table. A part at offset 0 parses with DXBC as its FourCC.

Open pull request #1944 ("reject a dxbc part inside the header or part table") carries this fix. Per the side-by-side test above, #343 (overlapping parts) does not cover this case on its own. The fork branches and the inline patch here make the same change, so please review or test #1944 rather than opening another pull request for it.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/777#issuecomment-7152314185) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T19:18:40Z at=2026-11-25T03:52:03Z --> Automated triage for the maintainers. Confirmed on `main`: `Container::parse` in `crates/victory-shader/src/dxbc.rs` reads each part at the offset from the table without checking that it lies past the header and the part table. A part at offset 0 parses with `DXBC` as its FourCC. Open pull request #1944 ("reject a dxbc part inside the header or part table") carries this fix. Per the side-by-side test above, #343 (overlapping parts) does not cover this case on its own. The fork branches and the inline patch here make the same change, so please review or test #1944 rather than opening another pull request for it. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:52 UTC · original

Opened PR #3251: the part table has to fit, and every part must start at or after HEADER_SIZE + 4 * count, so offset 0 no longer reads the DXBC magic as a FourCC. CI check passed (2m56s) and the PR is clean on main. The full shader suite with app-local WARP SM 6.6 gave 300 passed, 3 failed, 3 ignored, with the same three failures on 63bcca4 without the change; details are in the PR body. The coordination claim is in #1633.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 14:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/777#issuecomment-7195453171) Opened [PR #3251](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3251): the part table has to fit, and every part must start at or after HEADER_SIZE + 4 * count, so offset 0 no longer reads the DXBC magic as a FourCC. CI check passed (2m56s) and the PR is clean on main. The full shader suite with app-local WARP SM 6.6 gave 300 passed, 3 failed, 3 ignored, with the same three failures on 63bcca4 without the change; details are in the PR body. The [coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) is in #1633.
This discussion has been locked. Commenting is limited to contributors.
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#777
No description provided.