p2p-block: check for out-of-bounds indexing (#2187)

Return err on index OOB instead of panicking
This commit is contained in:
Julian Braha 2024-03-11 06:41:14 +00:00 committed by GitHub
parent cea93c444e
commit fdf1c18dd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -204,9 +204,12 @@ where
file.write_all(&data_buf[..block.size as usize]).await?;
let req = self.reqs.requests.get(self.i).ok_or_else(|| {
debug!("Vector read out of bounds!");
io::ErrorKind::Other
})?;
// TODO: Should this be `read == 0`
// TODO: Out of range protection on indexed access
if offset == self.reqs.requests[self.i].size {
if offset == req.size {
break;
}