Shader scan: a raw container's source is exactly the container #288

Open
github-bot wants to merge 7 commits from github-bot/gh-288 into main AGit
Owner

@⁠JordanFableFur on GitHub · 2026-11-24 23:18 UTC · original
JordanFableFur:fix/shader-scan-trailing-bytes → main · +125 −1 · 3 files · 7 commits · open

What

Source::Raw::bytes handed a run the whole slice from a DXBC magic to the file's end, and translate hashed those bytes (blake3::hash(&bytes)). A container with trailing file bytes after its declared length was then a different hash from the same container read at its own length, so VICTORY_TRANSLATE_ONLY=<hash> could not match it from a runtime log, and the longer slice flowed into VICTORY_DUMP_MATCH / VICTORY_FAIL_DUMP files.

The raw source now cuts to the container's parsed size, exposed as Container::size (the length parse already validates and cuts its own view to). Packed SGD5 records are unchanged: unpack returns exactly the record's bytes.

Fixes #246.

Testing

Synthetic: a one-part container (dxbc::build shape) scanned as a standalone file and as the same bytes followed by harmless tail now gives identical source bytes. New test a_container_and_its_copy_with_a_tail_hash_the_same in apps/victory/src/shader.rs.

  • cargo clippy --workspace --all-targets --locked -- -D warnings clean (cross-checked for the Windows target; no Windows machine here).
  • cargo test -p victory-shader -p victory-core -p victory-formats -p victory-pipeline -p xtask pass (209 tests). The victory bin's tests need the MSVC linker, not available on this Mac; the new test compiles there (cargo test -p victory --no-run passes up to linking).

AI use: written with a local GLM-5.3-Flash agent (pi); reviewed and posted with my approval. No game files were used.

**@⁠JordanFableFur** on GitHub · 2026-11-24 23:18 UTC · [original](https://github.com/fxceless/victory-fork/pull/288) `JordanFableFur:fix/shader-scan-trailing-bytes` → `main` · +125 −1 · 3 files · 7 commits · open ## What `Source::Raw::bytes` handed a run the whole slice from a DXBC magic to the file's end, and `translate` hashed those bytes (`blake3::hash(&bytes)`). A container with trailing file bytes after its declared length was then a different hash from the same container read at its own length, so `VICTORY_TRANSLATE_ONLY=<hash>` could not match it from a runtime log, and the longer slice flowed into `VICTORY_DUMP_MATCH` / `VICTORY_FAIL_DUMP` files. The raw source now cuts to the container's parsed size, exposed as `Container::size` (the length `parse` already validates and cuts its own view to). Packed SGD5 records are unchanged: `unpack` returns exactly the record's bytes. Fixes #246. ## Testing Synthetic: a one-part container (`dxbc::build` shape) scanned as a standalone file and as the same bytes followed by `harmless tail` now gives identical source bytes. New test `a_container_and_its_copy_with_a_tail_hash_the_same` in `apps/victory/src/shader.rs`. - `cargo clippy --workspace --all-targets --locked -- -D warnings` clean (cross-checked for the Windows target; no Windows machine here). - `cargo test -p victory-shader -p victory-core -p victory-formats -p victory-pipeline -p xtask` pass (209 tests). The `victory` bin's tests need the MSVC linker, not available on this Mac; the new test compiles there (`cargo test -p victory --no-run` passes up to linking). **AI use:** written with a local GLM-5.3-Flash agent (pi); reviewed and posted with my approval. No game files were used.
The raw-source iterator handed a run the whole slice from a DXBC magic to
the file's end, and the batch hashed those bytes. A container that carries
trailing file bytes after its declared length was then a different hash
from the same container read at its own length, so
VICTORY_TRANSLATE_ONLY could not match it from a runtime log, and the
longer slice flowed into diagnostic dumps.

Raw::bytes now cuts to the container's parsed size (Container::size, the
length parse validates and cuts its own view to); a test asserts the
standalone container and its copy with a tail give the same bytes.

AI use: written with a local GLM-5.3-Flash agent (pi); reviewed and
posted with my approval. No game files were used.
The size came from the last part's end: a container whose declared
length runs past its last part (padding inside, or part offsets out of
order) cut its source short, and the next parse then rejected what it
had accepted before. The parsed total is stored with the container and
returned.

A regression scans a container with room after its last part and reads
the declared length back.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:39:57 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:18 UTC · original · edited 2026-11-24 23:20 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:20:55.576828Z e40b8bb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:18 UTC · [original](https://github.com/fxceless/victory-fork/pull/288#issuecomment-7147251551) · edited 2026-11-24 23:20 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"e40b8bb0918d8f19382ebcf1670bd8ac613788df","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T23:20:55.576828Z">2026-11-24T23:20:55.576828Z</relative-time> | `e40b8bb` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠JordanFableFur on GitHub · 2026-11-25 00:32 UTC · original

Both findings addressed in c996e1c:

  • The test now scans the file and the standalone container separately (the buffer holds one container; the panic branch was reached).
  • Container::size returns the header's parsed total (stored on Container), not the last part's end, so padding inside the declared length survives; a regression scans a container with room after its last part and reads the declared length back.
**@⁠JordanFableFur** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/fxceless/victory-fork/pull/288#issuecomment-7148621984) Both findings addressed in c996e1c: - The test now scans the file and the standalone container separately (the buffer holds one container; the panic branch was reached). - `Container::size` returns the header's parsed total (stored on `Container`), not the last part's end, so padding inside the declared length survives; a regression scans a container with room after its last part and reads the declared length back.
Author
Owner

@⁠JordanFableFur on GitHub · 2026-11-25 01:46 UTC · original

For the duplicate sweep (#328 fixes the same issue): this PR was opened first (23:18 vs 23:34) and already carries resolutions to both of its review findings (the test scans the standalone separately; Container::size returns the header's declared length, so padding inside the declared total survives). Happy to withdraw it if #328 is preferred for other reasons.

**@⁠JordanFableFur** on GitHub · 2026-11-25 01:46 UTC · [original](https://github.com/fxceless/victory-fork/pull/288#issuecomment-7149942747) For the duplicate sweep (#328 fixes the same issue): this PR was opened first (23:18 vs 23:34) and already carries resolutions to both of its review findings (the test scans the standalone separately; `Container::size` returns the header's declared length, so padding inside the declared total survives). Happy to withdraw it if #328 is preferred for other reasons.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:20 UTC · original
On apps/victory/src/shader.rs line 264 (outdated):

@@ -225,3 +233,38 @@ fn format_instruction(i: &Instruction, wave64: bool) -> String {
     };
     format!("    {:06x}: {:<44} {text}", i.offset, words.join(" "))
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    /// One part of four bytes, no DXIL: enough for `sources` to find.
+    fn container() -> Vec<u8> {
+        let mut bytes = b"DXBC".to_vec();
+        bytes.extend([0; 16]); // digest
+        bytes.extend(1u16.to_le_bytes()); // version
+        bytes.extend(0u16.to_le_bytes());
+        let total = 0x20 + 4 + 8 + 4; // header, part table, part header, data
+        bytes.extend((total as u32).to_le_bytes());
+        bytes.extend(1u32.to_le_bytes()); // one part
+        bytes.extend(((0x20 + 4) as u32).to_le_bytes()); // the part at its end
+        bytes.extend(b"HASH");
+        bytes.extend(4u32.to_le_bytes());
+        bytes.extend([9; 4]);
+        bytes
+    }
+
+    #[test]
+    fn a_container_and_its_copy_with_a_tail_hash_the_same() {
+        let standalone = container();
+        let mut file = standalone.clone();
+        file.extend_from_slice(b"harmless tail");
+        let found = sources(&file);
+        let [a, b] = &found[..] else {
+            panic!("{} containers", found.len())

P1 Badge Scan both inputs before expecting two sources

The buffer contains only one DXBC container: standalone.clone() copies it once, and b"harmless tail" adds no second container. Consequently, sources(&file) returns one element, this pattern always takes the panic branch with 1 containers, and the Windows CI Tests step in .github/workflows/ci.yml fails. Scan standalone separately to compare its source bytes against the source found in file.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/288#discussion_r4687893096) On `apps/victory/src/shader.rs` line 264 (outdated): ```diff @@ -225,3 +233,38 @@ fn format_instruction(i: &Instruction, wave64: bool) -> String { }; format!(" {:06x}: {:<44} {text}", i.offset, words.join(" ")) } + +#[cfg(test)] +mod tests { + use super::*; + + /// One part of four bytes, no DXIL: enough for `sources` to find. + fn container() -> Vec<u8> { + let mut bytes = b"DXBC".to_vec(); + bytes.extend([0; 16]); // digest + bytes.extend(1u16.to_le_bytes()); // version + bytes.extend(0u16.to_le_bytes()); + let total = 0x20 + 4 + 8 + 4; // header, part table, part header, data + bytes.extend((total as u32).to_le_bytes()); + bytes.extend(1u32.to_le_bytes()); // one part + bytes.extend(((0x20 + 4) as u32).to_le_bytes()); // the part at its end + bytes.extend(b"HASH"); + bytes.extend(4u32.to_le_bytes()); + bytes.extend([9; 4]); + bytes + } + + #[test] + fn a_container_and_its_copy_with_a_tail_hash_the_same() { + let standalone = container(); + let mut file = standalone.clone(); + file.extend_from_slice(b"harmless tail"); + let found = sources(&file); + let [a, b] = &found[..] else { + panic!("{} containers", found.len()) ``` **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Scan both inputs before expecting two sources** The buffer contains only one DXBC container: `standalone.clone()` copies it once, and `b"harmless tail"` adds no second container. Consequently, `sources(&file)` returns one element, this pattern always takes the panic branch with `1 containers`, and the Windows CI `Tests` step in `.github/workflows/ci.yml` fails. Scan `standalone` separately to compare its source bytes against the source found in `file`. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:20 UTC · original
On crates/victory-shader/src/dxbc.rs line 120 (outdated):

@@ -109,6 +109,16 @@ impl<'a> Container<'a> {
     pub fn part(&self, fourcc: FourCC) -> Option<&Part<'a>> {
         self.parts.iter().find(|p| p.fourcc == fourcc)
     }
+
+    /// The container's byte length from its header: what `parse` cut its
+    /// view of `data` down to. A source holding the container inside a
+    /// larger file slices itself to this, so the same container gives the
+    /// same bytes and the same hash wherever it sits.
+    pub fn size(&self) -> usize {
+        self.parts
+            .last()
+            .map_or(HEADER_SIZE, |last| last.offset + 8 + last.data.len())

P2 Badge Return the header's declared container size

For containers that the parser accepts with an out-of-order part-offset table or padding inside the declared total size, the last table entry's end is smaller than the container length. For example, a 52-byte container whose final part ends at byte 48 returns 48 here. Source::Raw::bytes() then truncates it while leaving 52 in its header, so subsequent parsing fails and the shader survey and translator reject an input that worked before this change. Preserve and return the total read by parse instead of reconstructing it from the last part.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/288#discussion_r4687893104) On `crates/victory-shader/src/dxbc.rs` line 120 (outdated): ```diff @@ -109,6 +109,16 @@ impl<'a> Container<'a> { pub fn part(&self, fourcc: FourCC) -> Option<&Part<'a>> { self.parts.iter().find(|p| p.fourcc == fourcc) } + + /// The container's byte length from its header: what `parse` cut its + /// view of `data` down to. A source holding the container inside a + /// larger file slices itself to this, so the same container gives the + /// same bytes and the same hash wherever it sits. + pub fn size(&self) -> usize { + self.parts + .last() + .map_or(HEADER_SIZE, |last| last.offset + 8 + last.data.len()) ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Return the header's declared container size** For containers that the parser accepts with an out-of-order part-offset table or padding inside the declared total size, the last table entry's end is smaller than the container length. For example, a 52-byte container whose final part ends at byte 48 returns 48 here. `Source::Raw::bytes()` then truncates it while leaving 52 in its header, so subsequent parsing fails and the shader survey and translator reject an input that worked before this change. Preserve and return the `total` read by `parse` instead of reconstructing it from the last part. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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/288/head:github-bot/gh-288'
git switch 'github-bot/gh-288'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-288'
git switch 'github-bot/gh-288'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-288'
git switch 'github-bot/gh-288'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-288'
git switch 'main'
git merge --squash 'github-bot/gh-288'
git switch 'main'
git merge --ff-only 'github-bot/gh-288'
git switch 'main'
git merge 'github-bot/gh-288'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.