diff --git a/common/nymsphinx/anonymous-replies/src/reply_surb.rs b/common/nymsphinx/anonymous-replies/src/reply_surb.rs index 3ac7af8571..90bd892d78 100644 --- a/common/nymsphinx/anonymous-replies/src/reply_surb.rs +++ b/common/nymsphinx/anonymous-replies/src/reply_surb.rs @@ -19,6 +19,9 @@ use thiserror::Error; #[derive(Debug, Error)] pub enum ReplySurbError { + #[error("did not receive enough data to recover a reply SURB")] + TooShort, + #[error("tried to use reply SURB with an unpadded message")] UnpaddedMessageError, @@ -131,7 +134,9 @@ impl ReplySurb { } pub fn from_bytes(bytes: &[u8]) -> Result { - // TODO: introduce bound checks to guard us against out of bound reads + if bytes.len() <= SurbEncryptionKeySize::USIZE { + return Err(ReplySurbError::TooShort); + } let encryption_key = SurbEncryptionKey::try_from_bytes(&bytes[..SurbEncryptionKeySize::USIZE])?;