Skip to content

Commit

Permalink
Check size on insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Czabaniuk committed Apr 26, 2021
1 parent 58be28e commit 5e8acac
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ impl Blockstore {
shred: &Shred,
write_batch: &mut WriteBatch,
) -> Result<Vec<(u32, u32)>> {
use crate::shred::SHRED_PAYLOAD_SIZE;
let slot = shred.slot();
let index = u64::from(shred.index());

Expand Down Expand Up @@ -1414,6 +1415,14 @@ impl Blockstore {

// Commit step: commit all changes to the mutable structures at once, or none at all.
// We don't want only a subset of these changes going through.
if shred.payload.len() > SHRED_PAYLOAD_SIZE {
return Err(BlockstoreError::InvalidShredData(Box::new(
bincode::ErrorKind::Custom(format!(
"Data shred with slot {}, index {} has payload that is too large to be valid.",
slot, index
)),
)));
}
write_batch.put_bytes::<cf::ShredData>(
(slot, index),
// Payload will be padded out to SHRED_PAYLOAD_SIZE
Expand Down

0 comments on commit 5e8acac

Please sign in to comment.