From a91fc17f9c73930a0c0d765afa2b0e29ba616c22 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Sun, 5 May 2024 21:04:28 +0300 Subject: [PATCH] fix: add check before allocation in `SimpleCoder::decode_one()` --- crates/consensus/src/transaction/eip4844/builder.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/consensus/src/transaction/eip4844/builder.rs b/crates/consensus/src/transaction/eip4844/builder.rs index bb5967d9f3b..379583c8823 100644 --- a/crates/consensus/src/transaction/eip4844/builder.rs +++ b/crates/consensus/src/transaction/eip4844/builder.rs @@ -6,7 +6,7 @@ use c_kzg::{KzgCommitment, KzgProof}; use alloc::vec::Vec; use super::utils::WholeFe; -use alloy_eips::eip4844::{BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB}; +use alloy_eips::eip4844::{BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, MAX_BLOBS_PER_BLOCK}; use core::cmp; /// A builder for creating a [`BlobTransactionSidecar`]. @@ -196,6 +196,11 @@ impl SimpleCoder { return Ok(None); } + // if there are too many bytes + if num_bytes > BYTES_PER_BLOB * MAX_BLOBS_PER_BLOCK { + return Err(()); + } + let mut res = Vec::with_capacity(num_bytes); while num_bytes > 0 { let to_copy = cmp::min(31, num_bytes);