Skip to content

Commit

Permalink
Fix new vid panic on empty payload (#2733)
Browse files Browse the repository at this point in the history
* fix panic on empty payload

* better fix

* typo
  • Loading branch information
mrain authored Mar 7, 2025
1 parent 1161ba2 commit 2ee1513
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hotshot-types/src/data/ns_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ pub fn parse_ns_table(payload_byte_len: usize, bytes: &[u8]) -> Vec<Range<usize>
if num_entries
!= bytes.len().saturating_sub(NUM_NSS_BYTE_LEN)
/ NS_ID_BYTE_LEN.saturating_add(NS_OFFSET_BYTE_LEN)
|| (num_entries == 0 && payload_byte_len != 0)
{
tracing::warn!("Failed to parse the metadata as namespace table. Use a single namespace table instead.");
return vec![(0..payload_byte_len)];
}
// Early breaks for empty payload and namespace table
if num_entries == 0 {
return vec![(0..payload_byte_len)];
}
let mut l = 0;
for i in 0..num_entries {
let offset = NUM_NSS_BYTE_LEN + i * (NS_ID_BYTE_LEN + NS_OFFSET_BYTE_LEN) + NS_ID_BYTE_LEN;
Expand Down

0 comments on commit 2ee1513

Please sign in to comment.