Skip to content

security: eliminate panic sites in ember-core keyspace - #132

Merged
kacy merged 1 commit into
mainfrom
security/core-panic-elimination
Feb 14, 2026
Merged

security: eliminate panic sites in ember-core keyspace#132
kacy merged 1 commit into
mainfrom
security/core-panic-elimination

Conversation

@kacy

@kacy kacy commented Feb 14, 2026

Copy link
Copy Markdown
Owner

summary

  • replaced 6 sites of self.entries[key] direct hashmap indexing with safe .get()/.get_mut() + let-else patterns. direct indexing panics on missing keys; the safe patterns return early instead.
  • replaced expect() calls in zrem, hdel, and hincrby with let-else returns
  • hincrby and vadd type checks now use match on .get() instead of contains_key + direct index, eliminating a redundant lookup
  • format_float now checks i64::MIN..=i64::MAX range 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 pass
  • cargo clippy -p emberkv-core --features vector,protobuf -- -D warnings — clean
  • cargo fmt — clean

design considerations

  • the expect() calls in track_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 preceding insert_empty or ensure_collection_type call
  • cleanup_after_remove now uses if let Some(entry) instead of direct index, silently skipping the memory adjustment if the key is somehow missing (defensive, not expected to trigger)

…_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
kacy merged commit dfc6e26 into main Feb 14, 2026
6 of 7 checks passed
@kacy
kacy deleted the security/core-panic-elimination branch February 14, 2026 22:48
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant