pipeline: pin the cache key's field boundaries #574

Open
qnjk wants to merge 1 commit from qnjk/Darner:pipeline-cache-key-test into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: nothing. This is a tests-only change (no production line is edited), so it needs no A/B result and no gameplay run.

  • What it pins: the shader cache decides whether a stored translation is reused through CacheKey, whose body hashes three fields with one hand-written separator (crates/darner-pipeline/src/cache.rs, the &[0] in from_parts; CacheKey::new delegates to it):

    h.update(converter.id().as_bytes());
    h.update(&[0]);
    h.update(&converter.version().to_le_bytes());
    h.update(input);
    

    The separator is load-bearing and was untested and unexplained: without it, id "a" with version 0x62 and input b"\x00x" hashes the same eight bytes (61 62 00 00 00 00 00 78) as id "ab" with version 0 and input b"x", so one converter would be served the other's cached translation. Nothing said so, and a reader tidying the key path could delete it as redundant.

  • This change adds one #[cfg(test)] test with a local Converter whose id and version are settable.

How it was tested

  • Tested revision: e7c2646 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-pipeline --lib — 17 passed, 0 failed.
    • New cache::tests::cache_key_keeps_the_fields_apart pins three properties: (a) ("test.named", 3, b"input") equals itself; (b) ("a", 0x62, b"\x00x") != ("ab", 0, b"x") — the pair that collides when the 0x00 separator is dropped; (c) ("ab", 7, b"") != ("a", 7, b"b") — the pair that collides if the version is hashed before the id. Every assertion compares keys only: no hex digest and no golden value, so a blake3 bump cannot break it.
    • Fail-before, by putting the dangerous behaviour back twice (file copies, never git stash): deleting h.update(&[0]) makes (b) fail, and hashing the version before the id makes (c) fail.
    • cargo clippy --locked -p darner-pipeline --all-targets -- -D warnings passes.
  • Changes a default: no. Tests only.
  • A/B result: not applicable — tests-only change.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not run to completion here; the pre-existing darner-gpu test deadlock (#224) and the darner-shader waterfall fixture failure (#227) make the whole-workspace run non-green on this machine, and neither crate is touched. darner-pipeline's suite is green (17 passed).
  • Gameplay, when relevant: not applicable — tests-only change.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: the test pins the field boundaries, not the hash itself; a future field added without a separator would not be caught unless a collision pair is added for it. The doc comments the finding also suggested were deliberately left out (one would touch crates/darner-pipeline/src/lib.rs, which open PR #408 changes); the test's comment carries the explanation.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: tests-only change, stated at the top.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 576 files ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #408 changes crates/darner-pipeline/src/lib.rs (not cache.rs), which is why the doc comment the finding suggested was left out of this change. No open pull request changes crates/darner-pipeline/src/cache.rs, and no open or closed issue mentions CacheKey or the separator.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: nothing. This is a **tests-only** change (no production line is edited), so it needs no A/B result and no gameplay run. - What it pins: the shader cache decides whether a stored translation is reused through `CacheKey`, whose body hashes three fields with one hand-written separator (`crates/darner-pipeline/src/cache.rs`, the `&[0]` in `from_parts`; `CacheKey::new` delegates to it): ```rust h.update(converter.id().as_bytes()); h.update(&[0]); h.update(&converter.version().to_le_bytes()); h.update(input); ``` The separator is load-bearing and was untested and unexplained: without it, id `"a"` with version `0x62` and input `b"\x00x"` hashes the same eight bytes (`61 62 00 00 00 00 00 78`) as id `"ab"` with version `0` and input `b"x"`, so one converter would be served the other's cached translation. Nothing said so, and a reader tidying the key path could delete it as redundant. - This change adds one `#[cfg(test)]` test with a local `Converter` whose id and version are settable. ## How it was tested - Tested revision: `e7c2646` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-pipeline --lib` — 17 passed, 0 failed. - New `cache::tests::cache_key_keeps_the_fields_apart` pins three properties: (a) `("test.named", 3, b"input")` equals itself; (b) `("a", 0x62, b"\x00x") != ("ab", 0, b"x")` — the pair that collides when the `0x00` separator is dropped; (c) `("ab", 7, b"") != ("a", 7, b"b")` — the pair that collides if the version is hashed before the id. Every assertion compares keys only: no hex digest and no golden value, so a `blake3` bump cannot break it. - Fail-before, by putting the dangerous behaviour back twice (file copies, never `git stash`): deleting `h.update(&[0])` makes (b) fail, and hashing the version before the id makes (c) fail. - `cargo clippy --locked -p darner-pipeline --all-targets -- -D warnings` passes. - Changes a default: no. Tests only. - A/B result: not applicable — tests-only change. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not run to completion here; the pre-existing `darner-gpu` test deadlock (#224) and the `darner-shader` waterfall fixture failure (#227) make the whole-workspace run non-green on this machine, and neither crate is touched. `darner-pipeline`'s suite is green (17 passed). - Gameplay, when relevant: not applicable — tests-only change. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: the test pins the field boundaries, not the hash itself; a future field added without a separator would not be caught unless a collision pair is added for it. The doc comments the finding also suggested were deliberately left out (one would touch `crates/darner-pipeline/src/lib.rs`, which open PR #408 changes); the test's comment carries the explanation. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: tests-only change, stated at the top. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 576 files ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #408 changes `crates/darner-pipeline/src/lib.rs` (not `cache.rs`), which is why the doc comment the finding suggested was left out of this change. No open pull request changes `crates/darner-pipeline/src/cache.rs`, and no open or closed issue mentions `CacheKey` or the separator. - Replaces or overlaps: none found
`CacheKey::from_parts` hashes the converter id, one 0x00 byte and the
little-endian version before the input, and nothing said why that byte is
there or tested that it matters, so a reader tidying the key path could delete
it as redundant. Delete it and id "a" with version 0x62 and input b"\x00x"
hashes the same bytes as id "ab" with version 0 and input b"x", which would
serve one converter the other's cached translation. Hash the version first and
a trailing input byte stands in for the id the same way.

The new test pins the encoding as a property rather than a digest: identical
(id, version, input) triples must agree, the prefix-id pair must differ, and
the field-order pair must differ. It only compares keys, so a blake3 bump
cannot break it.
TrustNo1 changed title from [pr-tests] pipeline: pin the cache key's field boundaries to pipeline: pin the cache key's field boundaries 2026-12-06 03:26:58 +00:00
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 'pipeline-cache-key-test:qnjk-pipeline-cache-key-test'
git switch 'qnjk-pipeline-cache-key-test'

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 'qnjk-pipeline-cache-key-test'
git switch 'qnjk-pipeline-cache-key-test'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-pipeline-cache-key-test'
git switch 'qnjk-pipeline-cache-key-test'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-pipeline-cache-key-test'
git switch 'Main'
git merge --squash 'qnjk-pipeline-cache-key-test'
git switch 'Main'
git merge --ff-only 'qnjk-pipeline-cache-key-test'
git switch 'Main'
git merge 'qnjk-pipeline-cache-key-test'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
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
TrustNo1/Darner!574
No description provided.