overflow check in addition
This commit is contained in:
parent
0c7c34e609
commit
6b3f5c977a
@ -30,6 +30,8 @@ pub enum DecoderError {
|
||||
RlpInvalidIndirection,
|
||||
/// Declared length is inconsistent with data specified after.
|
||||
RlpInconsistentLengthAndData,
|
||||
/// Declared length is invalid and results in overflow
|
||||
RlpInvalidLength,
|
||||
/// Custom rlp decoding error.
|
||||
Custom(&'static str),
|
||||
}
|
||||
|
@ -371,7 +371,8 @@ impl<'a> BasicDecoder<'a> {
|
||||
}
|
||||
let len = decode_usize(&bytes[1..begin_of_value])?;
|
||||
|
||||
let last_index_of_value = begin_of_value + len;
|
||||
let last_index_of_value = begin_of_value.overflowing_add(len)
|
||||
.ok_or(DecoderError::RlpInvalidLength)?;
|
||||
if bytes.len() < last_index_of_value {
|
||||
return Err(DecoderError::RlpInconsistentLengthAndData);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user