Shaders: reject overlapping DXBC container parts #343

Open
pedrofort wants to merge 1 commit from upstream-pr/343 into main
pedrofort commented 2026-11-24 02:25:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pedrofort on 2026-11-24T02:25:58Z.


<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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573216353 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/343). Originally posted by [pedrofort](https://github.com/pedrofort) on 2026-11-24T02:25:58Z. --- <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>
jeremygold02 commented 2026-11-24 06:55:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:22:06Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121953600 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/343#issuecomment-7121953600). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:22:06Z. --- 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)
mercuryVM commented 2026-11-24 09:05:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T09:00:10Z.

Review: APPROVED


Tested 9459c12 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (267 passed, 0 failed). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. So the title's embedded containers still parse with the stricter check, which was the regression I wanted to rule out.

Sorting (offset, offset + 8 + len) and rejecting end > next start catches duplicate offsets and nested parts. Adjacent parts, including empty ones (end == next start), stay valid, and parts keeps its original order because only the copy is sorted.

No issues found. Nit: the PR description is pasted rich HTML, which renders oddly on GitHub. Plain Markdown would read better.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6036305988 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/343#pullrequestreview-6036305988). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T09:00:10Z. **Review:** APPROVED --- Tested 9459c12 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (267 passed, 0 failed). `victory translate <title exe> --validate --pipelines` gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. So the title's embedded containers still parse with the stricter check, which was the regression I wanted to rule out. Sorting `(offset, offset + 8 + len)` and rejecting `end > next start` catches duplicate offsets and nested parts. Adjacent parts, including empty ones (`end == next start`), stay valid, and `parts` keeps its original order because only the copy is sorted. No issues found. Nit: the PR description is pasted rich HTML, which renders oddly on GitHub. Plain Markdown would read better. AI-assisted (Claude Code).
sebastianspicker commented 2026-11-24 11:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sebastianspicker on 2026-11-24T11:02:06Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129568167 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/343#issuecomment-7129568167). Originally posted by [sebastianspicker](https://github.com/sebastianspicker) on 2026-11-24T11:02:06Z. --- 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.
Marvisak commented 2026-11-25 01:07:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:28:58Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148554854 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/343#issuecomment-7148554854). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:28:58Z. --- <!-- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/343:upstream-pr/343'
git switch 'upstream-pr/343'

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 'upstream-pr/343'
git switch 'upstream-pr/343'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/343'
git switch 'upstream-pr/343'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/343'
git switch 'main'
git merge --squash 'upstream-pr/343'
git switch 'main'
git merge --ff-only 'upstream-pr/343'
git switch 'main'
git merge 'upstream-pr/343'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!343
No description provided.