Skip to content

Commit

Permalink
fix: pass slice to RlpReceipt::rlp_decode_fields (#1696)
Browse files Browse the repository at this point in the history
* fix: pass slice to RlpReceipt::rlp_decode_fields

* doc
  • Loading branch information
klkvr authored Nov 27, 2024
1 parent e9051f8 commit 7ba1bff
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/consensus/src/receipt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy_primitives::Bloom;
use alloy_rlp::{BufMut, Header};
use alloy_rlp::{Buf, BufMut, Header};
use core::fmt;

mod envelope;
Expand Down Expand Up @@ -100,18 +100,22 @@ pub trait RlpReceipt: Sized {
if !header.list {
return Err(alloy_rlp::Error::UnexpectedString);
}
let remaining = buf.len();

if header.payload_length > remaining {
if header.payload_length > buf.len() {
return Err(alloy_rlp::Error::InputTooShort);
}

let this = Self::rlp_decode_fields_with_bloom(buf)?;
// Note: we pass a new slice to `Self::rlp_decode_fields_with_bloom` so that it knows the
// length of the payload specified in header.
let mut fields_buf = &buf[..header.payload_length];
let this = Self::rlp_decode_fields_with_bloom(&mut fields_buf)?;

if buf.len() + header.payload_length != remaining {
if !fields_buf.is_empty() {
return Err(alloy_rlp::Error::UnexpectedLength);
}

buf.advance(header.payload_length);

Ok(this)
}
}
Expand Down

0 comments on commit 7ba1bff

Please sign in to comment.