Avoid panic on invalid uint data.

This commit is contained in:
Gav Wood 2016-01-11 23:59:33 +01:00
parent d661116580
commit 65ab524053
3 changed files with 8 additions and 1 deletions

View File

@ -305,7 +305,11 @@ macro_rules! impl_uint_from_bytes {
($name: ident) => {
impl FromBytes for $name {
fn from_bytes(bytes: &[u8]) -> FromBytesResult<$name> {
Ok($name::from(bytes))
if bytes.len() <= $name::SIZE {
Ok($name::from(bytes))
} else {
Err(FromBytesError::DataIsTooLong)
}
}
}
}

View File

@ -1,4 +1,5 @@
#![feature(op_assign_traits)]
#![feature(associated_consts)]
//! Ethcore-util library
//!
//! ### Rust version:

View File

@ -50,6 +50,8 @@ macro_rules! construct_uint {
pub struct $name(pub [u64; $n_words]);
impl $name {
pub const SIZE: usize = $n_words * 8;
/// Conversion to u32
#[inline]
pub fn low_u32(&self) -> u32 {