security: eliminate panic sites in ember-core keyspace - #132
Merged
Conversation
…_float i64 cast - replaced 6 sites of self.entries[key] direct indexing with .get()/.get_mut() + let-else patterns to eliminate potential panics - replaced 2 expect() calls in zrem/hdel/srem with safe alternatives - hincrby and vadd type checks now use match on .get() instead of contains_key + direct index - format_float now checks i64 range before casting to prevent silent truncation on extreme float values
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
…_float i64 cast (#132) - replaced 6 sites of self.entries[key] direct indexing with .get()/.get_mut() + let-else patterns to eliminate potential panics - replaced 2 expect() calls in zrem/hdel/srem with safe alternatives - hincrby and vadd type checks now use match on .get() instead of contains_key + direct index - format_float now checks i64 range before casting to prevent silent truncation on extreme float values
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.
summary
self.entries[key]direct hashmap indexing with safe.get()/.get_mut()+let-elsepatterns. direct indexing panics on missing keys; the safe patterns return early instead.expect()calls inzrem,hdel, andhincrbywithlet-elsereturnshincrbyandvaddtype checks now usematchon.get()instead ofcontains_key+ direct index, eliminating a redundant lookupformat_floatnow checksi64::MIN..=i64::MAXrange before casting, preventing silent truncation on extreme float values (e.g. 1e18)what was tested
cargo test -p emberkv-core --features vector,protobuf— all 384 tests passcargo clippy -p emberkv-core --features vector,protobuf -- -D warnings— cleancargo fmt— cleandesign considerations
expect()calls intrack_size(lines 389, 392) are retained because the closure requires&mut Entry— there's no meaningful fallback if the key doesn't exist, and the invariant is maintained by the immediately precedinginsert_emptyorensure_collection_typecallcleanup_after_removenow usesif let Some(entry)instead of direct index, silently skipping the memory adjustment if the key is somehow missing (defensive, not expected to trigger)