From 5e8acace6b08b205fd278da226361985b9064f01 Mon Sep 17 00:00:00 2001 From: Steven Czabaniuk Date: Thu, 22 Apr 2021 11:06:28 -0500 Subject: [PATCH] Check size on insertion --- ledger/src/blockstore.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 016c6d7f962b9d..3665502c7bb6f0 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -1381,6 +1381,7 @@ impl Blockstore { shred: &Shred, write_batch: &mut WriteBatch, ) -> Result> { + use crate::shred::SHRED_PAYLOAD_SIZE; let slot = shred.slot(); let index = u64::from(shred.index()); @@ -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::( (slot, index), // Payload will be padded out to SHRED_PAYLOAD_SIZE