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

Commit 76d4064

Browse files
authored
Reject crazy timestamps instead of truncating. (#10575)
1 parent a03cf2e commit 76d4064

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ethcore/types/src/header.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
//! Block header.
1818
19-
use std::cmp;
2019
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP, keccak};
2120
use heapsize::HeapSizeOf;
2221
use ethereum_types::{H256, U256, Address, Bloom};
@@ -342,7 +341,7 @@ impl Decodable for Header {
342341
number: r.val_at(8)?,
343342
gas_limit: r.val_at(9)?,
344343
gas_used: r.val_at(10)?,
345-
timestamp: cmp::min(r.val_at::<U256>(11)?, u64::max_value().into()).as_u64(),
344+
timestamp: r.val_at(11)?,
346345
extra_data: r.val_at(12)?,
347346
seal: vec![],
348347
hash: keccak(r.as_raw()).into(),
@@ -445,4 +444,15 @@ mod tests {
445444

446445
assert_eq!(header_rlp, encoded_header);
447446
}
447+
448+
#[test]
449+
fn reject_header_with_large_timestamp() {
450+
// that's rlp of block header created with ethash engine.
451+
// The encoding contains a large timestamp (295147905179352825856)
452+
let header_rlp = "f901f9a0d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a05fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25a088d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158a007c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefba82524d891000000000000000000080a0a0349d8c3df71f1a48a9df7d03fd5f14aeee7d91332c009ecaff0a71ead405bd88ab4e252a7e8c2a23".from_hex().unwrap();
453+
454+
// This should fail decoding timestamp
455+
let header: Result<Header, _> = rlp::decode(&header_rlp);
456+
assert_eq!(header.unwrap_err(), rlp::DecoderError::RlpIsTooBig);
457+
}
448458
}

0 commit comments

Comments
 (0)