Skip to content

Commit

Permalink
fix(lzma): fixed panic in case of invalid lzma stream (#259)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Hennick <[email protected]>
  • Loading branch information
ideeockus and Pr0methean authored Nov 19, 2024
1 parent 0ea2744 commit ff877df
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/read/lzma.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -29,7 +29,11 @@ impl<R: Read> LzmaDecoder<R> {

impl<R: BufRead> Read for LzmaDecoder<R> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
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() {
Expand Down

0 comments on commit ff877df

Please sign in to comment.