add test
This commit is contained in:
parent
6b3f5c977a
commit
d30e47a50e
@ -371,7 +371,7 @@ 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.overflowing_add(len)
|
let last_index_of_value = begin_of_value.checked_add(len)
|
||||||
.ok_or(DecoderError::RlpInvalidLength)?;
|
.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);
|
||||||
@ -386,7 +386,7 @@ impl<'a> BasicDecoder<'a> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use UntrustedRlp;
|
use {UntrustedRlp, DecoderError};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rlp_display() {
|
fn test_rlp_display() {
|
||||||
@ -395,4 +395,12 @@ mod tests {
|
|||||||
let rlp = UntrustedRlp::new(&data);
|
let rlp = UntrustedRlp::new(&data);
|
||||||
assert_eq!(format!("{}", rlp), "[\"0x05\", \"0x010efbef67941f79b2\", \"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\", \"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470\"]");
|
assert_eq!(format!("{}", rlp), "[\"0x05\", \"0x010efbef67941f79b2\", \"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\", \"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470\"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn length_overflow() {
|
||||||
|
let bs = [0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe5];
|
||||||
|
let rlp = UntrustedRlp::new(&bs);
|
||||||
|
let res: Result<u8, DecoderError> = rlp.as_val();
|
||||||
|
assert_eq!(Err(DecoderError::RlpInvalidLength), res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user