From 849d60b47ab8bdce114d9332ec8ca68a14b93edf Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 20 Dec 2024 15:59:41 +1100 Subject: [PATCH] handle using padding after chunk --- rust/src/sans_io/read.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rust/src/sans_io/read.rs b/rust/src/sans_io/read.rs index bedd98185..20826c767 100644 --- a/rust/src/sans_io/read.rs +++ b/rust/src/sans_io/read.rs @@ -581,12 +581,19 @@ impl LinearReader { hasher.update(opcode_len_data); } state.compressed_remaining -= (9 + len) as u64; + state.uncompressed_remaining -= (9 + len) as u64; return Some(Ok(ReadAction::GetRecord { data, opcode })); } else { if self.decompressed_content.len() == 0 { self.decompressed_content.clear(); } - if state.compressed_remaining == 0 && self.decompressed_content.len() == 0 { + if state.uncompressed_remaining == 0 && self.decompressed_content.len() == 0 + { + // Some compressed data regions will have padding inserted at the end by + // the compressor, which we need to skip now that we have all the data we + // need. + state.padding_after_compressed_data += + check!(len_as_usize(state.compressed_remaining)); self.currently_reading = PaddingAfterChunk; continue; } @@ -1101,7 +1108,9 @@ mod tests { let mut f = std::fs::File::open("tests/data/break_zstd_decompression.mcap") .expect("failed to open file"); let blocksize: usize = 1024; - let mut reader = LinearReader::new(); + let mut reader = LinearReader::new_with_options( + LinearReaderOptions::default().with_prevalidate_chunk_crcs(true), + ); while let Some(action) = reader.next_action() { match action.expect("failed to get next action") { ReadAction::GetRecord { data: _, opcode } => {