Skip to content

Commit 587276c

Browse files
authored
read/elf: Read zstd frames in a loop until decompression is complete. (#730)
1 parent 34f6dce commit 587276c

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/read/mod.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -994,13 +994,30 @@ impl<'data> CompressedData<'data> {
994994
.read_error("Invalid zlib compressed data")?;
995995
}
996996
CompressionFormat::Zstandard => {
997-
let mut decoder = ruzstd::StreamingDecoder::new(self.data)
998-
.ok()
999-
.read_error("Invalid zstd compressed data")?;
1000-
decoder
1001-
.read_to_end(&mut decompressed)
1002-
.ok()
1003-
.read_error("Invalid zstd compressed data")?;
997+
let mut input = self.data;
998+
while !input.is_empty() {
999+
let mut decoder = match ruzstd::StreamingDecoder::new(&mut input) {
1000+
Ok(decoder) => decoder,
1001+
Err(
1002+
ruzstd::frame_decoder::FrameDecoderError::ReadFrameHeaderError(
1003+
ruzstd::frame::ReadFrameHeaderError::SkipFrame {
1004+
length,
1005+
..
1006+
},
1007+
),
1008+
) => {
1009+
input = &input
1010+
.get(length as usize..)
1011+
.read_error("Invalid zstd compressed data")?;
1012+
continue;
1013+
}
1014+
x => x.ok().read_error("Invalid zstd compressed data")?,
1015+
};
1016+
decoder
1017+
.read_to_end(&mut decompressed)
1018+
.ok()
1019+
.read_error("Invalid zstd compressed data")?;
1020+
}
10041021
}
10051022
_ => unreachable!(),
10061023
}

0 commit comments

Comments
 (0)