Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read/elf: Read zstd frames in a loop until decompression is complete. #730

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading