diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 5d5c7b01..53b59d12 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -282,7 +282,13 @@ impl Hasher for ThrottleKeyHasher { } fn write(&mut self, bytes: &[u8]) { - self.hash = u64::from_ne_bytes((&bytes[..std::mem::size_of::()]).try_into().unwrap()); + debug_assert!( + bytes.len() >= std::mem::size_of::(), + "ThrottleKeyHasher: input too short {bytes:?}" + ); + self.hash = bytes + .get(0..std::mem::size_of::()) + .map_or(0, |b| u64::from_ne_bytes(b.try_into().unwrap())); } }