Pipeline: delimit converter id in cache keys #922

Closed
enzoduarte1 wants to merge 1 commit from upstream-pr/922 into main
enzoduarte1 commented 2026-11-24 14:12:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by enzoduarte1 on 2026-11-24T14:12:11Z.


What

CacheKey::new fed the converter id, a single 0x00 separator, the 4-byte version and the input straight into BLAKE3. A &'static str may contain NUL, so the separator was ambiguous: id = "a\0", version = 1 and id = "a", version = 256 produced the same byte stream and therefore the same cache key. With two converters sharing a cache, whichever ran first could serve its output to the other.

The id is now length-prefixed with a u64, which makes every field boundary unambiguous while keeping the key stable for existing valid ids. A regression test asserts that the colliding pair and a differing-input pair produce distinct keys.

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-pipeline --lib: 4 passed.
  • git diff --check and rustfmt --check on the changed file: clean.
  • cargo xtask policy: 151 files ok. No game files or data taken from them were added.
  • Not tested: cargo test -p victory-loader --test load_probe; its fixture uses MSVC /DELAYLOAD, which MinGW rejects here (same failure on unmodified main).

Checklist

  • cargo fmt --all --check and cargo test --workspace pass — this workspace has pre-existing formatting diffs and the loader fixture limitation described above; the changed crate is clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6583724608 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/922). Originally posted by [enzoduarte1](https://github.com/enzoduarte1) on 2026-11-24T14:12:11Z. --- ## What `CacheKey::new` fed the converter id, a single `0x00` separator, the 4-byte version and the input straight into BLAKE3. A `&'static str` may contain NUL, so the separator was ambiguous: `id = "a\0", version = 1` and `id = "a", version = 256` produced the same byte stream and therefore the same cache key. With two converters sharing a cache, whichever ran first could serve its output to the other. The id is now length-prefixed with a `u64`, which makes every field boundary unambiguous while keeping the key stable for existing valid ids. A regression test asserts that the colliding pair and a differing-input pair produce distinct keys. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-pipeline --lib`: 4 passed. - `git diff --check` and `rustfmt --check` on the changed file: clean. - `cargo xtask policy`: 151 files ok. No game files or data taken from them were added. - Not tested: `cargo test -p victory-loader --test load_probe`; its fixture uses MSVC `/DELAYLOAD`, which MinGW rejects here (same failure on unmodified `main`). ## Checklist - [ ] `cargo fmt --all --check` and `cargo test --workspace` pass — this workspace has pre-existing formatting diffs and the loader fixture limitation described above; the changed crate is clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
DenRakEiw commented 2026-11-24 15:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T14:21:15Z.

Review: APPROVED


Tested head f7bce85 (fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-pipeline: 5 passed, 0 failed (including cache::tests::id_and_version_are_delimited)
  • cargo clippy -p victory-pipeline --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean fix preventing converter-ID/version boundary collisions in cache keys. Approving.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6040907789 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/922#pullrequestreview-6040907789). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T14:21:15Z. **Review:** APPROVED --- Tested head `f7bce85` (fast-forward on `main` `ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC): - `cargo test -p victory-pipeline`: **5 passed, 0 failed** (including `cache::tests::id_and_version_are_delimited`) - `cargo clippy -p victory-pipeline --all-targets`: **0 warnings** - `cargo xtask policy`: ok Clean fix preventing converter-ID/version boundary collisions in cache keys. Approving. AI-assisted (Gemini 4 Neon).
mercuryVM commented 2026-11-24 15:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T14:32:04Z.

Review: APPROVED


Tested f7bce85 on Windows 11, RTX 5070, MSVC: cargo test -p victory-pipeline 5 passed, including id_and_version_are_delimited, and cargo clippy -p victory-pipeline --all-targets is clean.

  • Length-prefixing the converter id removes the NUL ambiguity ("a\0"/v1 against "a"/v256), which is the right fix for a key fed to one hash stream.
  • Side effect to note in the release notes: every existing cache key changes, so the first run after this rebuilds the whole converted-asset cache once. That's harmless, but users with large caches will see a one-time slowdown.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6041124201 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/922#pullrequestreview-6041124201). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T14:32:04Z. **Review:** APPROVED --- Tested f7bce85 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-pipeline` 5 passed, including `id_and_version_are_delimited`, and `cargo clippy -p victory-pipeline --all-targets` is clean. - Length-prefixing the converter id removes the NUL ambiguity (`"a\0"`/v1 against `"a"`/v256), which is the right fix for a key fed to one hash stream. - Side effect to note in the release notes: every existing cache key changes, so the first run after this rebuilds the whole converted-asset cache once. That's harmless, but users with large caches will see a one-time slowdown. AI-assisted (Claude Code).
shortselow-byte commented 2026-11-24 15:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T14:21:10Z.


Tested at head f7bce85 (base ffe310e) on Windows 11, Rust 1.98.1, x86_64-pc-windows-msvc:

  • cargo test --locked -p victory-pipeline: 5 passed.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean.
  • rustfmt --check on cache.rs: clean.

The fix itself looks right, but the regression test does not catch the bug. With main's key code (id, 0x00, version) put back, id_and_version_are_delimited still passes: "a\0"/1 and "a"/256 with the same empty input hash 7 bytes vs 6, so they never collided. The colliding pair needs the input to absorb the shifted byte:

// Old stream: "a\0" 00 | 01 00 00 00 | ""  ==  "a" 00 | 00 01 00 00 | "\0"
assert_ne!(
    CacheKey::new(&Keyed("a\0", 1), b""),
    CacheKey::new(&Keyed("a", 256), b"\0")
);

With the old key code this assertion fails (both keys 8502be22…ed13); with this PR it passes. Suggest using this pair in the test.

One nit on the description: the length prefix changes the hashed bytes for every id, so every existing cache key changes (existing caches miss once and rebuild). Probably fine, but "keeping the key stable for existing valid ids" isn't accurate.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134234342 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/922#issuecomment-7134234342). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-24T14:21:10Z. --- Tested at head `f7bce85` (base `ffe310e`) on Windows 11, Rust 1.98.1, `x86_64-pc-windows-msvc`: - `cargo test --locked -p victory-pipeline`: 5 passed. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and with `--all-features`: clean. - `rustfmt --check` on `cache.rs`: clean. The fix itself looks right, but the regression test does not catch the bug. With `main`'s key code (`id`, `0x00`, version) put back, `id_and_version_are_delimited` still passes: `"a\0"`/1 and `"a"`/256 with the same empty input hash 7 bytes vs 6, so they never collided. The colliding pair needs the input to absorb the shifted byte: ```rust // Old stream: "a\0" 00 | 01 00 00 00 | "" == "a" 00 | 00 01 00 00 | "\0" assert_ne!( CacheKey::new(&Keyed("a\0", 1), b""), CacheKey::new(&Keyed("a", 256), b"\0") ); ``` With the old key code this assertion fails (both keys `8502be22…ed13`); with this PR it passes. Suggest using this pair in the test. One nit on the description: the length prefix changes the hashed bytes for every id, so every existing cache key changes (existing caches miss once and rebuild). Probably fine, but "keeping the key stable for existing valid ids" isn't accurate.
MichaelSmithAI commented 2026-11-24 15:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T14:31:06Z.


I checked the on-disk behavior behind the earlier review’s compatibility note. A Linux fixture prepopulated the old path for the ordinary converter ID test.upper, version 1, input abc, with output ABC. On f7bce85 the first lookup ran the converter and published ABC at a different path. The second lookup hit that new entry. The original file still contained ABC, and the converter ran exactly once across the two lookups. This measures a cold lookup for an existing input and no change in its converted bytes.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134506315 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/922#issuecomment-7134506315). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T14:31:06Z. --- I checked the on-disk behavior behind the earlier review’s compatibility note. A Linux fixture prepopulated the old path for the ordinary converter ID `test.upper`, version 1, input `abc`, with output `ABC`. On f7bce85 the first lookup ran the converter and published `ABC` at a different path. The second lookup hit that new entry. The original file still contained `ABC`, and the converter ran exactly once across the two lookups. This measures a cold lookup for an existing input and no change in its converted bytes.
Zipettte commented 2026-11-24 16:05:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:41:02Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at f7bce85: cargo test -p victory-pipeline passes, 5 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136437211 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/922#issuecomment-7136437211). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T15:41:02Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at f7bce85: `cargo test -p victory-pipeline` passes, 5 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
upstream-sync closed this pull request 2026-11-25 01:04:55 +00:00
Marvisak commented 2026-11-25 01:07:51 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).

Length-prefixes the converter id in CacheKey against a collision that needs a NUL inside an id; ids are string literals in our code (only "shader.dxil" exists). Contrary to the body, the new byte stream changes every key, so the whole translated-shader cache misses once and the old entries stay orphaned in the same translator folder: a cost without a benefit.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148541176 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/922#issuecomment-7148541176). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:28:09Z. --- Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current). Length-prefixes the converter id in CacheKey against a collision that needs a NUL inside an id; ids are string literals in our code (only "shader.dxil" exists). Contrary to the body, the new byte stream changes every key, so the whole translated-shader cache misses once and the old entries stay orphaned in the same translator folder: a cost without a benefit. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!922
No description provided.