Skip to content

Commit

Permalink
read/elf: Read zstd frames in a loop until decompression is complete. (
Browse files Browse the repository at this point in the history
  • Loading branch information
khuey authored Sep 14, 2024
1 parent 34f6dce commit 587276c
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,13 +994,30 @@ impl<'data> CompressedData<'data> {
.read_error("Invalid zlib compressed data")?;
}
CompressionFormat::Zstandard => {
let mut decoder = ruzstd::StreamingDecoder::new(self.data)
.ok()
.read_error("Invalid zstd compressed data")?;
decoder
.read_to_end(&mut decompressed)
.ok()
.read_error("Invalid zstd compressed data")?;
let mut input = self.data;
while !input.is_empty() {
let mut decoder = match ruzstd::StreamingDecoder::new(&mut input) {
Ok(decoder) => decoder,
Err(
ruzstd::frame_decoder::FrameDecoderError::ReadFrameHeaderError(
ruzstd::frame::ReadFrameHeaderError::SkipFrame {
length,
..
},
),
) => {
input = &input
.get(length as usize..)
.read_error("Invalid zstd compressed data")?;
continue;
}
x => x.ok().read_error("Invalid zstd compressed data")?,
};
decoder
.read_to_end(&mut decompressed)
.ok()
.read_error("Invalid zstd compressed data")?;
}
}
_ => unreachable!(),
}
Expand Down

0 comments on commit 587276c

Please sign in to comment.