Skip to content

Commit 9559580

Browse files
committed
better fix
1 parent 82be459 commit 9559580

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

hotshot-types/src/data/ns_table.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ pub fn parse_ns_table(payload_byte_len: usize, bytes: &[u8]) -> Vec<Range<usize>
2626
return vec![(0..payload_byte_len)];
2727
}
2828
let num_entries = u32::from_le_bytes(bytes[..NUM_NSS_BYTE_LEN].try_into().unwrap()) as usize;
29-
if num_entries == 0
30-
|| num_entries
31-
!= bytes.len().saturating_sub(NUM_NSS_BYTE_LEN)
32-
/ NS_ID_BYTE_LEN.saturating_add(NS_OFFSET_BYTE_LEN)
29+
if num_entries
30+
!= bytes.len().saturating_sub(NUM_NSS_BYTE_LEN)
31+
/ NS_ID_BYTE_LEN.saturating_add(NS_OFFSET_BYTE_LEN)
32+
|| (num_entries == 0 && payload_byte_len != 0)
3333
{
3434
tracing::warn!("Failed to parse the metadata as namespace table. Use a single namespace table instead.");
3535
return vec![(0..payload_byte_len)];
3636
}
37+
// Early breaks for empty payload and namespae table
38+
if num_entries == 0 {
39+
return vec![(0..payload_byte_len)];
40+
}
3741
let mut l = 0;
3842
for i in 0..num_entries {
3943
let offset = NUM_NSS_BYTE_LEN + i * (NS_ID_BYTE_LEN + NS_OFFSET_BYTE_LEN) + NS_ID_BYTE_LEN;

0 commit comments

Comments
 (0)