overflow check in addition

This commit is contained in:
NikVolf 2017-08-03 21:35:51 +03:00
parent 0c7c34e609
commit 6b3f5c977a
2 changed files with 4 additions and 1 deletions

View File

@ -30,6 +30,8 @@ pub enum DecoderError {
RlpInvalidIndirection, RlpInvalidIndirection,
/// Declared length is inconsistent with data specified after. /// Declared length is inconsistent with data specified after.
RlpInconsistentLengthAndData, RlpInconsistentLengthAndData,
/// Declared length is invalid and results in overflow
RlpInvalidLength,
/// Custom rlp decoding error. /// Custom rlp decoding error.
Custom(&'static str), Custom(&'static str),
} }

View File

@ -371,7 +371,8 @@ impl<'a> BasicDecoder<'a> {
} }
let len = decode_usize(&bytes[1..begin_of_value])?; 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 { if bytes.len() < last_index_of_value {
return Err(DecoderError::RlpInconsistentLengthAndData); return Err(DecoderError::RlpInconsistentLengthAndData);
} }