Repository navigation
Conversation
VarianceBuilder::finalize() separated each (name, value) dimension with a
single 0x00 byte. That separator is ambiguous for any field that can itself
contain 0x00, so two distinct variance sets could serialize to identical bytes
and collide onto the same cache key (e.g. {a: "b", c: "d"} and {a: "b\0c\0d"}).
Length-prefix each field instead, so the hashed bytes are an injective encoding
of the (name, value) pairs regardless of their contents. Field boundaries are
then explicit rather than delimiter-based. Adds a regression test.
Note: this changes variance hashes, so a cache storing entries with variance
sees a one-time cold start for those entries (same migration caveat as the
earlier namespace removal).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
VarianceBuilder::finalize()serialized each(name, value)variance dimension into the hash input separated by a single0x00byte. That separator is ambiguous for any field that can itself contain0x00: two different sets of dimensions can serialize to identical bytes and therefore hash to the same cache-variance key.For example, these currently produce the same variance key:
{ "a": "b", "c": "d" }{ "a": "b\0c\0d" }Change
Length-prefix each field so the hashed bytes are an injective encoding of the
(name, value)pairs — field boundaries become explicit rather than delimiter-based, so no field's contents can reproduce a boundary. Behavior is unchanged for all0x00-free inputs (which includes every HTTP header value). Adds a regression test (test_field_boundaries_are_unambiguous).This mirrors the reasoning already documented for the removed
CacheKey::newnamespaceargument, whose concatenation "preserves its ambiguous component boundaries".Compatibility
Variance hashes change, so a cache that stores entries carrying variance sees a one-time cold start for those entries. Entries without variance are unaffected (
finalize()returnsNoneandcombined_bin()falls back to the primary key). This is the same migration caveat noted for the namespace removal.Testing
5/5 pass (4 existing + the new regression test).