Repository navigation
minor: fix potential soundness hole in fsb dictionary builder - #12397
Merged
Merged
Conversation
Jefffrey
commented
Nov 22, 2026
| fn get_or_insert_key(&mut self, value: impl AsRef<[u8]>) -> Result<K::Native, ArrowError> { | ||
| let value_bytes: &[u8] = value.as_ref(); | ||
|
|
||
| fn get_or_insert_key(&mut self, value_bytes: &[u8]) -> Result<K::Native, ArrowError> { |
Contributor
Author
There was a problem hiding this comment.
the 'hole' is that it could be feasible for an implementation of AsRef<[u8]> to actually return two different values in subsequent calls, in a safe way. so we need to ensure we call it only once, and then pass through &[u8] which is now safe to handle, as passing through impl AsRef<[u8]> gives control over to the implementation
a nice side effect is that i find this to just be cleaner, and we no longer need to make get_or_insert_key generic over impl AsRef<[u8]>
Rich-T-kid
approved these changes
Nov 22, 2026
Rich-T-kid
left a comment
Contributor
There was a problem hiding this comment.
nice find, thanks @Jefffrey
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 22, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 23, 2026
Phoenix500526
pushed a commit
to Phoenix500526/arrow-rs
that referenced
this pull request
Nov 23, 2026
…#12408) Same as - apache#12397 But for `FixedSizeBinaryBuilder`
compiler-segfault
added a commit
to compiler-segfault/arrow-rs
that referenced
this pull request
Nov 26, 2026
`GenericByteDictionaryBuilder::get_or_insert_key` hashed `value.as_ref()` and then called `value.as_ref()` again through `storage.append_value(value)`. `AsRef` is not required to be idempotent, so the stored bytes could differ from the hashed bytes: the dictionary then holds a value filed under the wrong hash, and a later append of the value that was actually hashed adds a duplicate entry. Store the same `&T::Native` that was hashed, the way apache#12397 did it for the fixed-size binary dictionary builder. Fixes apache#12424.
compiler-segfault
added a commit
to compiler-segfault/arrow-rs
that referenced
this pull request
Nov 26, 2026
`GenericByteDictionaryBuilder::get_or_insert_key` hashed `value.as_ref()` and then called `value.as_ref()` again through `storage.append_value(value)`. `AsRef` is not required to be idempotent, so the stored bytes could differ from the hashed bytes: the dictionary then holds a value filed under the wrong hash, and a later append of the value that was actually hashed adds a duplicate entry. Store the same `&T::Native` that was hashed, the way apache#12397 did it for the fixed-size binary dictionary builder. Fixes apache#12424.
dragonknightk
pushed a commit
to dragonknightk/arrow-rs
that referenced
this pull request
Nov 26, 2026
Fixes apache#12424. `GenericByteDictionaryBuilder::get_or_insert_key` hashed `value.as_ref()` to look the value up, then called `value.as_ref()` a second time inside the insert closure through `storage.append_value(value)`. `AsRef` is not required to be idempotent, so the stored bytes could differ from the bytes that were hashed: the dictionary then holds a value filed under the wrong hash, and a later append of the value that was actually hashed adds a duplicate entry. The builder now stores the same `&T::Native` that it hashed. This is the same fix apache#12397 made for `FixedSizeBinaryDictionaryBuilder`, which had the identical pattern. Verification: - New test `test_dictionary_builder_hashes_and_stores_the_same_bytes` uses an `AsRef<str>` that returns a different value on each call; on `main` it fails with `left: 2, right: 1` (the dictionary ends up with two entries and keys `[0, 1]` instead of one entry with `[0, 0]`). It passes with this change. - `cargo test -p arrow-array`: 767 passed, 1 ignored. - `cargo fmt --all -- --check` and `cargo clippy -p arrow-array --all-targets --all-features -- -D warnings` are clean. The text above was drafted with an AI assistant; I ran the tests myself. Co-authored-by: compiler-segfault <[email protected]>
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.
Which issue does this PR close?
Rationale for this change
Fix a potential soundness issue, see comments for more details
What changes are included in this PR?
Refactoring code to avoid issue.
Are these changes tested?
Existing tests for fsb dictionary builder
Are there any significant user-facing changes?
No