Shaders: reject overlapping DXBC container parts #343

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

@⁠pedrofort on GitHub · 2026-11-24 02:25 UTC · original
pedrofort:fix-dxbc-overlap → main · +52 −0 · 1 files · 1 commits · open

<head></head>

Problem

Container::parse() validates individual DXBC part boundaries but does not check whether multiple parts overlap.

As a result, malformed containers with duplicate part offsets or nested parts are accepted.

Fix

  • Collect and sort the byte ranges of parsed parts.

  • Reject intersecting ranges with ShaderError::Malformed.

  • Preserve the original part order.

  • Allow valid adjacent parts, including empty payloads.

This complements #326, which addresses parts overlapping the container header rather than each other.

Verification

Apple M5, macOS arm64, Rust 1.98.1, base commit d2a4bae.

Test | Before | After -- | -- | -- Duplicate offsets | FAIL | PASS Nested part | FAIL | PASS Adjacent empty parts | PASS | PASS Complete shader unit test suite | — | 59/59 PASS

Clippy (--lib -- -D warnings): clean.

The existing non-Windows constant_color dead-code warning is unchanged.

All test containers are synthetic. No game data was used.

AI-assisted implementation and test preparation (ChatGPT), with tests executed locally on Apple Silicon.

**@⁠pedrofort** on GitHub · 2026-11-24 02:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/343) `pedrofort:fix-dxbc-overlap` → `main` · +52 −0 · 1 files · 1 commits · open <head></head><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Problem</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><code><span>Container::parse()</span></code><span><span class="Apple-converted-space"> </span>validates individual DXBC part boundaries but does not check whether multiple parts overlap.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>As a result, malformed containers with duplicate part offsets or nested parts are accepted.</span></p><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Fix</span></h2><ul style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><li><p><span>Collect and sort the byte ranges of parsed parts.</span></p></li><li><p><span>Reject intersecting ranges with<span class="Apple-converted-space"> </span></span><code><span>ShaderError::Malformed</span></code><span>.</span></p></li><li><p><span>Preserve the original part order.</span></p></li><li><p><span>Allow valid adjacent parts, including empty payloads.</span></p></li></ul><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>This complements #326, which addresses parts overlapping the container header rather than each other.</span></p><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Verification</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Apple M5, macOS arm64, Rust 1.98.1, base commit<span class="Apple-converted-space"> </span></span><code><span>d2a4bae</span></code><span>.</span></p> Test | Before | After -- | -- | -- Duplicate offsets | FAIL | PASS Nested part | FAIL | PASS Adjacent empty parts | PASS | PASS Complete shader unit test suite | — | 59/59 PASS <p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Clippy (</span><code><span>--lib -- -D warnings</span></code><span>): clean.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>The existing non-Windows<span class="Apple-converted-space"> </span></span><code><span>constant_color</span></code><span><span class="Apple-converted-space"> </span>dead-code warning is unchanged.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>All test containers are synthetic. No game data was used.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>AI-assisted implementation and test preparation (ChatGPT), with tests executed locally on Apple Silicon.</span></p>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:59 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:22 UTC · original

Tested PR #343 at head 9459c12d2e3a3d48ac2e073e7d3d9a888bfa913d (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at 9459c12d2e3a3d48ac2e073e7d3d9a888bfa913d.

  • cargo test --locked -p victory-shader overlap_ — passed (ok. 3 passed; 0 failed; 0 ignored; 0 measured; 69 filtered out; finished in 0.00s ); cases: dxbc::tests::overlap_rejects_duplicate_offsets, dxbc::tests::overlap_accepts_adjacent_empty_parts, dxbc::tests::overlap_rejects_nested_part.

Behavior covered: Checks duplicate and nested DXBC part offsets are rejected while adjacent empty parts remain accepted.
Code: crates/victory-shader/src/dxbc.rs

**@⁠jeremygold02** on GitHub · 2026-11-24 04:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/343#issuecomment-7121953600) Tested PR #343 at head `9459c12d2e3a3d48ac2e073e7d3d9a888bfa913d` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `9459c12d2e3a3d48ac2e073e7d3d9a888bfa913d`. - `cargo test --locked -p victory-shader overlap_` — passed (ok. 3 passed; 0 failed; 0 ignored; 0 measured; 69 filtered out; finished in 0.00s ); cases: dxbc::tests::overlap_rejects_duplicate_offsets, dxbc::tests::overlap_accepts_adjacent_empty_parts, dxbc::tests::overlap_rejects_nested_part. Behavior covered: Checks duplicate and nested DXBC part offsets are rejected while adjacent empty parts remain accepted. Code: [crates/victory-shader/src/dxbc.rs](https://github.com/Marvisak/VIctory/blob/9459c12d2e3a3d48ac2e073e7d3d9a888bfa913d/crates/victory-shader/src/dxbc.rs)
Author
Owner

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

I think #326 covers this. I copied the three tests from this PR unchanged into #326 at bf594d5, and all three pass there. On main (ffe310e), overlap_rejects_duplicate_offsets and overlap_rejects_nested_part fail as expected, and overlap_accepts_adjacent_empty_parts passes. #326 also checks a part reaching into an earlier one and parts inside the header, so it's the wider version of the same fix.

If the maintainer prefers this one because it's smaller, the sort-then-windows(2) check looks right to me; adjacent and empty parts stay valid. Otherwise this could close once #326 merges.

AI-assisted.

**@⁠sebastianspicker** on GitHub · 2026-11-24 11:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/343#issuecomment-7129568167) I think #326 covers this. I copied the three tests from this PR unchanged into #326 at `bf594d5`, and all three pass there. On `main` (`ffe310e`), `overlap_rejects_duplicate_offsets` and `overlap_rejects_nested_part` fail as expected, and `overlap_accepts_adjacent_empty_parts` passes. #326 also checks a part reaching into an earlier one and parts inside the header, so it's the wider version of the same fix. If the maintainer prefers this one because it's smaller, the sort-then-`windows(2)` check looks right to me; adjacent and empty parts stay valid. Otherwise this could close once #326 merges. AI-assisted.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:28 UTC · original

Automated triage for the maintainers.

Needs work. The overlap check in Container::parse (crates/victory-shader/src/dxbc.rs) is correct (sorted ranges, windows(2), touching and empty parts allowed); note the slice reads were already bounds-checked, so overlaps were never a memory-safety issue. Container::parse also reads the title's own shader containers, so a new rejection makes affected programs fail to translate, and this was tested only on synthetic containers. Please run translation over the title's shaders (e.g. victory translate --list) and report that no program that translated before is now refused; that would make it mergeable. #326 also contains an overlap check inside a large bundle; this smaller PR could be the one to take.

CI: no check runs on the head commit.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/343#issuecomment-7148554854) <!-- victory-triage v1 head=9459c12d2e3a3d48ac2e073e7d3d9a888bfa913d verdict=needs-work at=2026-11-25T00:19:34Z --> Automated triage for the maintainers. **Needs work.** The overlap check in `Container::parse` (`crates/victory-shader/src/dxbc.rs`) is correct (sorted ranges, `windows(2)`, touching and empty parts allowed); note the slice reads were already bounds-checked, so overlaps were never a memory-safety issue. `Container::parse` also reads the title's own shader containers, so a new rejection makes affected programs fail to translate, and this was tested only on synthetic containers. Please run translation over the title's shaders (e.g. `victory translate --list`) and report that no program that translated before is now refused; that would make it mergeable. #326 also contains an overlap check inside a large bundle; this smaller PR could be the one to take. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
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 origin '+refs/pull/343/head:github-bot/gh-343'
git switch 'github-bot/gh-343'

Merge

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