Repository navigation
Conversation
A degree of one passed the power-of-two check but makes every trie level consume zero bits of the hash, so inserting two distinct keys recursed forever and overflowed the stack. Fixes orium#113.
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.
Requested by winshyon
Description
HashTrieMap::new_with_degree(1)(and every other constructor that funnels intonew_with_hasher_and_degree_and_ptr_kind, including theHashTrieSetones) was accepted because 1 is apower of two. With degree 1,
index_from_hashusestrailing_zeros() == 0bits per level and a mask of 0,so every key maps to index 0 at every depth and the shift never reaches the end of the hash. Two distinct
keys therefore can never be separated, and
insertrecurses until the stack overflows.This adds
assert!(degree >= 2, "degree must be at least 2")next to the existing power-of-two andupper-bound assertions, so the bad degree is rejected at construction time as the issue suggests, and adds a
#[should_panic]regression test.Motivation / disclosure: I had some spare AI-assistant quota (Claude Code) and am using it to try to
help projects with open good-first-issues. The change was prepared with Claude Code and verified as listed
below. If it doesn't fit, isn't up to your bar, or you'd simply rather not take it — please feel free to
close it, no hard feelings at all 🙂
Related issue
Closes #113
Checklist
test_new_with_degree_one_panicsfails without the fix ("test did not panic as expected") and passes with it;cargo test --all-targets --all-features(277 passed),cargo test --all-targets --no-default-features(259 passed),cargo test --doc --all-features(29 passed),cargo fmt -- --check,cargo clippy --all-targets -- -D warnings,cargo doc --no-deps --all-featuresall clean withRUSTFLAGS=-DwarningsCHANGELOG.mdis updated (if applicable) — n/a, happy to add arelease-notes.mdentry if you'd like one🤖 Generated with Claude Code