patches bug in data-shred index sanitize (#24707)

https://github.com/solana-labs/solana/pull/24653
introduced an off-by-one error in data-shred index sanitize.
This commit is contained in:
behzad nouri 2022-04-26 21:10:27 +00:00 committed by GitHub
parent 7de339cb5c
commit 913ad79cd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -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(),
});
@ -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!(