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

Open
JordanFableFur wants to merge 7 commits from upstream-pr/288 into main
JordanFableFur commented 2026-11-24 23:18:17 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-24T23:18:17Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593376873 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/288). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-24T23:18:17Z. --- ## 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.
chatgpt-codex-connector[bot commented 2026-11-25 00:09:39 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:20:52Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e40b8bb091

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:fxceless/victory-fork:review:6048973380 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/288#pullrequestreview-6048973380). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:20:52Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `e40b8bb091` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-25 00:10:06 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:18:33Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7147251551 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/288#issuecomment-7147251551). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:18:33Z. --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-25 00:10:13 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:20:53Z.

Code review location: apps/victory/src/shader.rs; line 264

@@ -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 👍 / 👎.

<!-- greyfinch-sync:fxceless/victory-fork:review-comment:4687893096 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/288#discussion_r4687893096). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:20:53Z. **Code review location:** `apps/victory/src/shader.rs`; line 264 ~~~~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 -->
chatgpt-codex-connector[bot commented 2026-11-25 00:10:13 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:20:53Z.

Code review location: crates/victory-shader/src/dxbc.rs; line 120

@@ -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 👍 / 👎.

<!-- greyfinch-sync:fxceless/victory-fork:review-comment:4687893104 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/288#discussion_r4687893104). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:20:53Z. **Code review location:** `crates/victory-shader/src/dxbc.rs`; line 120 ~~~~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 -->
JordanFableFur commented 2026-11-25 01:12:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-25T00:32:54Z.


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.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7148621984 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/288#issuecomment-7148621984). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-25T00:32:54Z. --- 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 commented 2026-11-25 02:10:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JordanFableFur on 2026-11-25T01:46:35Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149942747 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/288#issuecomment-7149942747). Originally posted by [JordanFableFur](https://github.com/JordanFableFur) on 2026-11-25T01:46:35Z. --- 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.
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/288:upstream-pr/288'
git switch 'upstream-pr/288'

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/288'
git switch 'upstream-pr/288'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/288'
git switch 'upstream-pr/288'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/288'
git switch 'main'
git merge --squash 'upstream-pr/288'
git switch 'main'
git merge --ff-only 'upstream-pr/288'
git switch 'main'
git merge 'upstream-pr/288'
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
fxceless/victory-fork!288
No description provided.