X-Git-Url: https://git.nihav.org/?p=nihav.git;a=blobdiff_plain;f=nihav-core%2Fsrc%2Fcompr%2Fdeflate.rs;h=3462a4034996445255b9ad0f93f79671fae12e9e;hp=da37fde37df255faa698b82bd66597a8347f8d05;hb=b7c882c1ce6f86c07c2340751200e3a060942826;hpb=c96ad969bab50f17ffe6c421375e68fe0cc9648f diff --git a/nihav-core/src/compr/deflate.rs b/nihav-core/src/compr/deflate.rs index da37fde..3462a40 100644 --- a/nihav-core/src/compr/deflate.rs +++ b/nihav-core/src/compr/deflate.rs @@ -227,6 +227,7 @@ pub struct Inflate { buf: [u8; 65536], bpos: usize, output_idx: usize, + full_pos: usize, state: InflateState, final_block: bool, @@ -305,6 +306,7 @@ impl Inflate { buf: [0; 65536], bpos: 0, output_idx: 0, + full_pos: 0, state: InflateState::Start, final_block: false, @@ -321,10 +323,11 @@ impl Inflate { fn put_literal(&mut self, val: u8) { self.buf[self.bpos] = val; self.bpos = (self.bpos + 1) & (self.buf.len() - 1); + self.full_pos += 1; } fn lz_copy(&mut self, offset: usize, len: usize, dst: &mut [u8]) -> DecompressResult<()> { let mask = self.buf.len() - 1; - if offset > self.output_idx { + if offset > self.full_pos { return Err(DecompressError::InvalidData); } let cstart = (self.bpos.wrapping_sub(offset)) & mask; @@ -333,6 +336,7 @@ impl Inflate { dst[i] = self.buf[(cstart + i) & mask]; } self.bpos = (self.bpos + len) & mask; + self.full_pos += len; Ok(()) } ///! Reports whether decoder has finished decoding the input. @@ -355,6 +359,7 @@ impl Inflate { ///! ///! [`DecompressError::ShortData`]: ../enum.DecompressError.html#variant.ShortData ///! [`DecompressError::OutputFull`]: ../enum.DecompressError.html#variant.OutputFull + #[allow(clippy::comparison_chain)] pub fn decompress_data(&mut self, src: &[u8], dst: &mut [u8], continue_block: bool) -> DecompressResult { if src.is_empty() || dst.is_empty() { return Err(DecompressError::InvalidArgument);