Skip to content

Commit e66ab0b

Browse files
committed
fix: cap VecOf pre-allocation to prevent OOM on malformed input
A crafted event log with a large count (e.g. 0xFFFFFFFF) could cause Vec::with_capacity to attempt allocating ~4GB before any decode occurs. Cap the pre-allocation to 1024; the Vec will still grow as needed via push if the actual count is larger.
1 parent 06a2347 commit e66ab0b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

cc-eventlog/src/codecs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<I: Decode + Into<u32> + Copy, T: Decode> Decode for VecOf<I, T> {
2525
fn decode<In: Input>(input: &mut In) -> Result<Self, scale::Error> {
2626
let decoded_len = I::decode(input)?;
2727
let len = decoded_len.into() as usize;
28-
let mut inner = Vec::with_capacity(len);
28+
let mut inner = Vec::with_capacity(len.min(1024));
2929
for _ in 0..len {
3030
inner.push(T::decode(input)?);
3131
}

0 commit comments

Comments
 (0)