Skip to content

Commit ff877df

Browse files
fix(lzma): fixed panic in case of invalid lzma stream (#259)
Co-authored-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
1 parent 0ea2744 commit ff877df

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/read/lzma.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use lzma_rs::decompress::{Options, Stream, UnpackedSize};
22
use std::collections::VecDeque;
3-
use std::io::{BufRead, Read, Result, Write};
3+
use std::io::{BufRead, Error, ErrorKind, Read, Result, Write};
44

55
const OPTIONS: Options = Options {
66
unpacked_size: UnpackedSize::ReadFromHeader,
@@ -29,7 +29,11 @@ impl<R: Read> LzmaDecoder<R> {
2929

3030
impl<R: BufRead> Read for LzmaDecoder<R> {
3131
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
32-
let mut bytes_read = self.stream.get_output_mut().unwrap().read(buf)?;
32+
let mut bytes_read = self
33+
.stream
34+
.get_output_mut()
35+
.ok_or(Error::new(ErrorKind::InvalidData, "Invalid LZMA stream"))?
36+
.read(buf)?;
3337
while bytes_read < buf.len() {
3438
let compressed_bytes = self.compressed_reader.fill_buf()?;
3539
if compressed_bytes.is_empty() {

0 commit comments

Comments
 (0)