Merge pull request #47 from mguillemot-tel/master

Fix is_int() panic with untrusted input
This commit is contained in:
David 2018-09-04 06:25:02 +02:00 committed by GitHub
commit 5b31d79589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -223,7 +223,10 @@ impl<'a> Rlp<'a> {
match self.bytes[0] {
0...0x80 => true,
0x81...0xb7 => self.bytes[1] != 0,
b @ 0xb8...0xbf => self.bytes[1 + b as usize - 0xb7] != 0,
b @ 0xb8...0xbf => {
let payload_idx = 1 + b as usize - 0xb7;
payload_idx < self.bytes.len() && self.bytes[payload_idx] != 0
},
_ => false
}
}

View File

@ -429,3 +429,12 @@ fn test_rlp_stream_unbounded_list() {
stream.complete_unbounded_list();
assert!(stream.is_finished());
}
#[test]
fn test_rlp_is_int() {
for b in 0xb8..0xc0 {
let data: Vec<u8> = vec![b];
let rlp = Rlp::new(&data);
assert_eq!(rlp.is_int(), false);
}
}