untrusted rlp data length check

This commit is contained in:
Nikolay Volf
2016-01-25 16:23:05 +04:00
parent eed88df0d4
commit b2050fa639
3 changed files with 20 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ use self::json_tests::rlp as rlptest;
use std::{fmt, cmp};
use std::str::FromStr;
use rlp;
use rlp::{UntrustedRlp, RlpStream, View, Stream};
use rlp::{UntrustedRlp, RlpStream, View, Stream, DecoderError};
use uint::U256;
#[test]
@@ -351,3 +351,14 @@ fn test_decoding_array() {
assert_eq!(arr[0], 5);
assert_eq!(arr[1], 2);
}
#[test]
fn test_rlp_data_length_check()
{
let data = vec![0x84, b'c', b'a', b't'];
let rlp = UntrustedRlp::new(&data);
let as_val: Result<String, DecoderError> = rlp.as_val();
assert_eq!(Err(DecoderError::RlpInconsistentLengthAndData), as_val);
}