Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
[ethcore/builtin]: do not panic in blake2pricer on short input (#11180)
Browse files Browse the repository at this point in the history
* [ethcore/builtin]: do not panic in blake2pricer on short input

* [ethcore/builtin]: add a test for blake2pricer
  • Loading branch information
ordian authored and niklasad1 committed Nov 5, 2019
1 parent eec9e5b commit e403efd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ethcore/builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ impl Pricer for Blake2FPricer {
const FOUR: usize = std::mem::size_of::<u32>();
// Returning zero if the conversion fails is fine because `execute()` will check the length
// and bail with the appropriate error.
let rounds = u32::from_be_bytes(rounds_bytes.try_into().unwrap_or([0u8; 4]));
if input.len() < FOUR {
return U256::zero();
}
let (rounds_bytes, _) = input.split_at(FOUR);
let rounds = u32::from_be_bytes(rounds_bytes.try_into().unwrap_or([0u8; FOUR]));
U256::from(*self as u128 * rounds as u128)
}
}
Expand Down

0 comments on commit e403efd

Please sign in to comment.