Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
first attempt at fuzzer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrichter committed Aug 19, 2022
1 parent 275b761 commit 0e38435
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ipld/dag_cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ pub fn read_f64<R: Read>(r: &mut R) -> CborResult<f64> {

#[inline]
pub fn read_bytes<R: Read>(r: &mut R, len: usize) -> CborResult<Vec<u8>> {
if len > 64 * 1024 {
return Err(CborError::LengthOutOfRange);
}
let mut buf = vec![0; len];
r.read_exact(&mut buf)?;
Ok(buf)
Expand All @@ -410,6 +413,9 @@ pub fn read_str<R: Read>(r: &mut R, len: usize) -> CborResult<String> {

#[inline]
pub fn read_list<R: Read, T: ReadCbor>(r: &mut R, len: usize) -> CborResult<Vec<T>> {
if len.saturating_mul(std::mem::size_of::<T>()) > 64 * 1024 {
return Err(CborError::LengthOutOfRange);
}
let mut list: Vec<T> = Vec::with_capacity(len);
for _ in 0..len {
list.push(T::read_cbor(r)?);
Expand Down

0 comments on commit 0e38435

Please sign in to comment.