Merge pull request #36 from gavofyork/gav

Avoid panic on invalid uint data.
This commit is contained in:
Marek Kotewicz 2016-01-12 00:01:32 +01:00
commit b6b65ea182
3 changed files with 8 additions and 1 deletions

View File

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

View File

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

View File

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