diff --git a/ipld/amt/src/node.rs b/ipld/amt/src/node.rs index e093e402e..2d5becf09 100644 --- a/ipld/amt/src/node.rs +++ b/ipld/amt/src/node.rs @@ -576,6 +576,9 @@ where match self { Node::Leaf { vals } => { let start_idx = start_at.map_or(0, |s| s.saturating_sub(offset)); + if start_idx as usize >= vals.len() { + return Ok((false, 0, None)); + } let mut keep_going = true; for (i, v) in (start_idx..).zip(vals[start_idx as usize..].iter()) { let idx = offset + i; @@ -595,6 +598,9 @@ where let idx: usize = ((start_at.map_or(0, |s| s.saturating_sub(offset))) / nfh) .try_into() .expect("index overflow"); + if idx >= links.len() { + return Ok((false, 0, None)); + } for (i, link) in (idx..).zip(links[idx..].iter()) { if let Some(l) = link { let offs = offset + (i as u64 * nfh);