Skip to content

Commit

Permalink
patches bug in data-shred index sanitize (#24707)
Browse files Browse the repository at this point in the history
#24653
introduced an off-by-one error in data-shred index sanitize.
  • Loading branch information
behzadnouri committed Apr 26, 2022
1 parent 7de339c commit 913ad79
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl Shred {
}
match self.shred_type() {
ShredType::Data => {
if self.index() as usize > MAX_DATA_SHREDS_PER_SLOT {
if self.index() as usize >= MAX_DATA_SHREDS_PER_SLOT {
return Err(Error::InvalidDataShredIndex {
index: self.index(),
});
Expand Down Expand Up @@ -2136,6 +2136,14 @@ mod tests {
})
);
}
{
let mut shred = shred.clone();
shred.common_header.index = MAX_DATA_SHREDS_PER_SLOT as u32;
assert_matches!(
shred.sanitize(),
Err(Error::InvalidDataShredIndex { index: 32768 })
);
}
{
shred.data_header.size = shred.payload().len() as u16 + 1;
assert_matches!(
Expand Down

0 comments on commit 913ad79

Please sign in to comment.