X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fcompr%2Fdeflate.rs;h=fa318a473e84647e9ca281cfa6fc868c243c812a;hb=1f50a8cf7cce96c3b2b67343dc57ca17854c0094;hp=8e91caa369789267c4dec7d08468cf50f244dbd6;hpb=0443d0c5f73697d5eb59081be3cde9fb02dc3e70;p=nihav.git diff --git a/nihav-core/src/compr/deflate.rs b/nihav-core/src/compr/deflate.rs index 8e91caa..fa318a4 100644 --- a/nihav-core/src/compr/deflate.rs +++ b/nihav-core/src/compr/deflate.rs @@ -72,6 +72,7 @@ impl CodebookDescReader for FixedLenCodeReader { else if idx < 280 { 7 } else { 8 } } + #[allow(clippy::identity_op)] fn code(&mut self, idx: usize) -> u32 { let base = idx as u32; let bits = self.bits(idx); @@ -355,7 +356,7 @@ impl Inflate { ///! [`DecompressError::ShortData`]: ../enum.DecompressError.html#variant.ShortData ///! [`DecompressError::OutputFull`]: ../enum.DecompressError.html#variant.OutputFull pub fn decompress_data(&mut self, src: &[u8], dst: &mut [u8], continue_block: bool) -> DecompressResult { - if src.len() == 0 || dst.len() == 0 { + if src.is_empty() || dst.is_empty() { return Err(DecompressError::InvalidArgument); } let mut csrc = if !continue_block { @@ -597,16 +598,15 @@ impl Inflate { self.state = InflateState::End; return Err(DecompressError::InvalidHeader); } - let rpt; - if mode == 0 { - if self.cur_len_idx == 0 { - self.state = InflateState::End; - return Err(DecompressError::InvalidHeader); - } - rpt = self.all_lengths[self.cur_len_idx - 1]; - } else { - rpt = 0; - } + let rpt = if mode == 0 { + if self.cur_len_idx == 0 { + self.state = InflateState::End; + return Err(DecompressError::InvalidHeader); + } + self.all_lengths[self.cur_len_idx - 1] + } else { + 0 + }; for _ in 0..len { self.all_lengths[self.cur_len_idx] = rpt; self.cur_len_idx += 1; @@ -716,7 +716,14 @@ impl Inflate { ///! Decompresses input data into output returning the uncompressed data length. pub fn uncompress(src: &[u8], dst: &mut [u8]) -> DecompressResult { let mut inflate = Self::new(); - inflate.decompress_data(src, dst, false) + let off = if src.len() > 2 && src[0] == 0x78 && src[1] == 0x9C { 2 } else { 0 }; + inflate.decompress_data(&src[off..], dst, false) + } +} + +impl Default for Inflate { + fn default() -> Self { + Self::new() } } @@ -747,7 +754,7 @@ fn lengths_to_codes(lens: &[u8], codes: &mut [ShortCodebookDesc]) -> DecompressR *codes = ShortCodebookDesc { code: 0, bits: 0 }; } } - + Ok(()) } @@ -757,6 +764,7 @@ struct GzipCRC32 { } impl GzipCRC32 { + #[allow(clippy::unreadable_literal)] fn new() -> Self { let mut tab = [0u32; 256]; for i in 0..256 {