From ff877df42544ac589549b0bc5fd5eae04ea50cda Mon Sep 17 00:00:00 2001 From: Radmir <33758991+ideeockus@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:55:47 +0300 Subject: [PATCH] fix(lzma): fixed panic in case of invalid lzma stream (#259) Co-authored-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> --- src/read/lzma.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/read/lzma.rs b/src/read/lzma.rs index e4720914..f883a7b9 100644 --- a/src/read/lzma.rs +++ b/src/read/lzma.rs @@ -1,6 +1,6 @@ use lzma_rs::decompress::{Options, Stream, UnpackedSize}; use std::collections::VecDeque; -use std::io::{BufRead, Read, Result, Write}; +use std::io::{BufRead, Error, ErrorKind, Read, Result, Write}; const OPTIONS: Options = Options { unpacked_size: UnpackedSize::ReadFromHeader, @@ -29,7 +29,11 @@ impl LzmaDecoder { impl Read for LzmaDecoder { fn read(&mut self, buf: &mut [u8]) -> Result { - let mut bytes_read = self.stream.get_output_mut().unwrap().read(buf)?; + let mut bytes_read = self + .stream + .get_output_mut() + .ok_or(Error::new(ErrorKind::InvalidData, "Invalid LZMA stream"))? + .read(buf)?; while bytes_read < buf.len() { let compressed_bytes = self.compressed_reader.fill_buf()?; if compressed_bytes.is_empty() {