Don't panic in import_block if invalid rlp (#8522)
* Don't panic in import_block if invalid rlp * Remove redundant type annotation * Replace RLP header view usage with safe decoding Using the view will panic with invalid RLP. Here we use Rlp decoding directly which will return a `Result<_, DecoderError>`. While this path currently should not have any invalid RLP - it makes it safer if ever called with invalid RLP from other code paths.
This commit is contained in:
committed by
Marek Kotewicz
parent
eec7364760
commit
66c0638f3b
@@ -36,6 +36,7 @@ use views::BlockView;
|
||||
use ethkey::KeyPair;
|
||||
use transaction::{PendingTransaction, Transaction, Action, Condition};
|
||||
use miner::MinerService;
|
||||
use rlp::{RlpStream, EMPTY_LIST_RLP};
|
||||
use tempdir::TempDir;
|
||||
|
||||
#[test]
|
||||
@@ -111,6 +112,25 @@ fn imports_good_block() {
|
||||
assert!(!block.into_inner().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_to_import_block_with_invalid_rlp() {
|
||||
use error::{BlockImportError, BlockImportErrorKind};
|
||||
|
||||
let client = generate_dummy_client(6);
|
||||
let mut rlp = RlpStream::new_list(3);
|
||||
rlp.append_raw(&EMPTY_LIST_RLP, 1); // empty header
|
||||
rlp.append_raw(&EMPTY_LIST_RLP, 1);
|
||||
rlp.append_raw(&EMPTY_LIST_RLP, 1);
|
||||
let invalid_header_block = rlp.out();
|
||||
|
||||
match client.import_block(invalid_header_block) {
|
||||
Err(BlockImportError(BlockImportErrorKind::Decoder(_), _)) => (), // all good
|
||||
Err(_) => panic!("Should fail with a decoder error"),
|
||||
Ok(_) => panic!("Should not import block with invalid header"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn query_none_block() {
|
||||
let tempdir = TempDir::new("").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user