Skip to content

Commit

Permalink
fix panic on empty payload
Browse files Browse the repository at this point in the history
  • Loading branch information
mrain committed Mar 7, 2025
1 parent 7608376 commit 82be459
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions hotshot-types/src/data/ns_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ pub fn parse_ns_table(payload_byte_len: usize, bytes: &[u8]) -> Vec<Range<usize>
return vec![(0..payload_byte_len)];
}
let num_entries = u32::from_le_bytes(bytes[..NUM_NSS_BYTE_LEN].try_into().unwrap()) as usize;
if num_entries
!= bytes.len().saturating_sub(NUM_NSS_BYTE_LEN)
/ NS_ID_BYTE_LEN.saturating_add(NS_OFFSET_BYTE_LEN)
if num_entries == 0
|| num_entries
!= bytes.len().saturating_sub(NUM_NSS_BYTE_LEN)
/ NS_ID_BYTE_LEN.saturating_add(NS_OFFSET_BYTE_LEN)
{
tracing::warn!("Failed to parse the metadata as namespace table. Use a single namespace table instead.");
return vec![(0..payload_byte_len)];
Expand Down

0 comments on commit 82be459

Please sign in to comment.