Skip to content

Commit

Permalink
Fix panic in get_logs. (#1484)
Browse files Browse the repository at this point in the history
If `to_epoch` is too large, `get_pivot_block_arena_index` will panic.
  • Loading branch information
peilun-conflux authored and Peilun Li committed May 25, 2020
1 parent 4f0a564 commit fad1395
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 7 additions & 0 deletions core/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,13 @@ impl ConsensusGraph {
});
}

if to_epoch > inner.best_epoch_number() {
return Err(FilterError::OutOfBoundEpochNumber {
to_epoch,
max_epoch: inner.best_epoch_number(),
});
}

let blooms = filter.bloom_possibilities();
let mut blocks = vec![];
for epoch_number in from_epoch..(to_epoch + 1) {
Expand Down
26 changes: 23 additions & 3 deletions primitives/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@ use std::{error, fmt};
/// Errors concerning log filtering.
pub enum FilterError {
/// Filter has wrong epoch numbers set.
InvalidEpochNumber { from_epoch: u64, to_epoch: u64 },
InvalidEpochNumber {
from_epoch: u64,
to_epoch: u64,
},

OutOfBoundEpochNumber {
to_epoch: u64,
max_epoch: u64,
},

/// Roots for verifying the requested epochs are unavailable.
UnableToVerify { epoch: u64, latest_verifiable: u64 },
UnableToVerify {
epoch: u64,
latest_verifiable: u64,
},

/// The block requested does not exist
UnknownBlock { hash: H256 },
UnknownBlock {
hash: H256,
},

/// Filter error with custom error message (e.g. timeout)
Custom(String),
Expand All @@ -51,6 +64,13 @@ impl fmt::Display for FilterError {
"Filter has wrong epoch numbers set (from: {}, to: {})",
from_epoch, to_epoch
},
OutOfBoundEpochNumber {
to_epoch,
max_epoch,
} => format! {
"Filter to_epoch is larger than the current best_epoch (to: {}, max: {})",
to_epoch, max_epoch,
},
UnableToVerify {
epoch,
latest_verifiable,
Expand Down

0 comments on commit fad1395

Please sign in to comment.