diff --git a/scale-decode/src/visitor/types/bit_sequence.rs b/scale-decode/src/visitor/types/bit_sequence.rs index 10824dd..c11fbf5 100644 --- a/scale-decode/src/visitor/types/bit_sequence.rs +++ b/scale-decode/src/visitor/types/bit_sequence.rs @@ -46,14 +46,16 @@ impl<'scale> BitSequence<'scale> { Ok(bytes_after) } else { let decoder = decode_using_format_from(self.bytes, self.format)?; - Ok(&self.bytes[decoder.encoded_size()..]) + self.bytes.get(decoder.encoded_size()..).ok_or_else(|| DecodeError::NotEnoughInput) } } /// Return a decoder to decode the bits in this bit sequence. pub fn decode(&mut self) -> Result, DecodeError> { let decoder = decode_using_format_from(self.bytes, self.format)?; - self.bytes_after = Some(&self.bytes[decoder.encoded_size()..]); + self.bytes_after = Some( + &self.bytes.get(decoder.encoded_size()..).ok_or_else(|| DecodeError::NotEnoughInput)?, + ); Ok(decoder) } }