Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/sats/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,12 @@ impl<T, const N: usize> GrowingVec<T> for SmallVec<[T; N]> {

/// A basic implementation of `ArrayVisitor::visit` using the provided size hint.
pub fn array_visit<'de, A: ArrayAccess<'de>, V: GrowingVec<A::Element>>(mut access: A) -> Result<V, A::Error> {
let mut v = V::try_with_capacity(access.size_hint().unwrap_or(0))?;
// Don’t blindly trust length prefixes when reserving initial capacity
// for decoding array elements, as malformed input could generate a huge allocation,
// potentially resulting in an OOM kill.
const RESERVE_ARRAY_ELEMENTS: usize = 4096;
let cap = access.size_hint().unwrap_or(0);
let mut v = V::try_with_capacity(cap.min(RESERVE_ARRAY_ELEMENTS))?;
while let Some(x) = access.next_element()? {
v.push(x)
}
Expand Down
Loading