From 999d41d438b9a68f4b0c3994e95261eddebb29ad Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Sun, 2 Jun 2024 12:25:02 -0700 Subject: [PATCH 1/6] feat: Update dependencies --- Cargo.toml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9fc6571b..d59d9176 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zip" -version = "2.1.1" +version = "2.1.2" authors = [ "Mathijs van de Nes ", "Marli Frost ", @@ -30,34 +30,34 @@ aes = { version = "0.8.4", optional = true } bzip2 = { version = "0.4.4", optional = true } chrono = { version = "0.4.38", optional = true } constant_time_eq = { version = "0.3.0", optional = true } -crc32fast = "1.4.0" +crc32fast = "1.4.2" displaydoc = { version = "0.2.4", default-features = false } -flate2 = { version = "1.0.28", default-features = false, optional = true } +flate2 = { version = "1.0.30", default-features = false, optional = true } indexmap = "2" hmac = { version = "0.12.1", optional = true, features = ["reset"] } memchr = "2.7.2" pbkdf2 = { version = "0.12.2", optional = true } rand = { version = "0.8.5", optional = true } sha1 = { version = "0.10.6", optional = true } -thiserror = "1.0.48" +thiserror = "1.0.61" time = { workspace = true, optional = true, features = [ "std", ] } -zeroize = { version = "1.6.0", optional = true, features = ["zeroize_derive"] } +zeroize = { version = "1.8.1", optional = true, features = ["zeroize_derive"] } zstd = { version = "0.13.1", optional = true, default-features = false } zopfli = { version = "0.8.1", optional = true } deflate64 = { version = "0.1.8", optional = true } lzma-rs = { version = "0.3.0", default-features = false, optional = true } [target.'cfg(any(all(target_arch = "arm", target_pointer_width = "32"), target_arch = "mips", target_arch = "powerpc"))'.dependencies] -crossbeam-utils = "0.8.19" +crossbeam-utils = "0.8.20" [target.'cfg(fuzzing)'.dependencies] arbitrary = { version = "1.3.2", features = ["derive"] } [dev-dependencies] bencher = "0.1.5" -getrandom = { version = "0.2.14", features = ["js", "std"] } +getrandom = { version = "0.2.15", features = ["js", "std"] } walkdir = "2.5.0" time = { workspace = true, features = ["formatting", "macros"] } anyhow = "1" From 888e5fac16cac17f97df3019e3da870ab7218129 Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Sun, 2 Jun 2024 16:09:19 -0700 Subject: [PATCH 2/6] fix: Switch padding field ID to one documented in APPNOTE --- src/write.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/write.rs b/src/write.rs index c5c8798e..ec708d59 100644 --- a/src/write.rs +++ b/src/write.rs @@ -881,9 +881,12 @@ impl ZipWriter { )); }; if pad_length >= 4 { - // Add an extra field to the extra_data + // Add an extra field to the extra_data, per APPNOTE 4.6.11 let pad_body = vec![0; pad_length - 4]; - writer.write_all(b"za").map_err(ZipError::from)?; // 0x617a + if pad_body.len() >= 2 { + pad_body[0..2].write_u16_le(options.alignment)?; + } + writer.write_u16_le(0xa11e)?; writer .write_u16_le(pad_body.len() as u16) .map_err(ZipError::from)?; From 8e92cc4d81b83960566ad288d7e3d947ab57ea5a Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Sun, 2 Jun 2024 17:03:32 -0700 Subject: [PATCH 3/6] chore: Fix a build error --- src/unstable.rs | 2 +- src/write.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/unstable.rs b/src/unstable.rs index 85f2b396..102c4336 100644 --- a/src/unstable.rs +++ b/src/unstable.rs @@ -43,7 +43,7 @@ pub trait LittleEndianWriteExt: Write { } } -impl LittleEndianWriteExt for W {} +impl LittleEndianWriteExt for W {} /// Helper methods for reading unsigned integers in little-endian form. pub trait LittleEndianReadExt: Read { diff --git a/src/write.rs b/src/write.rs index ec708d59..f753cb83 100644 --- a/src/write.rs +++ b/src/write.rs @@ -21,7 +21,7 @@ use std::default::Default; use std::fmt::{Debug, Formatter}; use std::io; use std::io::prelude::*; -use std::io::{BufReader, SeekFrom}; +use std::io::{BufReader, Cursor, SeekFrom}; use std::marker::PhantomData; use std::mem; use std::str::{from_utf8, Utf8Error}; @@ -882,9 +882,9 @@ impl ZipWriter { }; if pad_length >= 4 { // Add an extra field to the extra_data, per APPNOTE 4.6.11 - let pad_body = vec![0; pad_length - 4]; + let mut pad_body = vec![0; pad_length - 4]; if pad_body.len() >= 2 { - pad_body[0..2].write_u16_le(options.alignment)?; + Cursor::new(&mut pad_body).write_u16_le(options.alignment)?; } writer.write_u16_le(0xa11e)?; writer From 79fc5a9cdde4735ecb3390aef488bab4151f87ab Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Sun, 2 Jun 2024 17:06:10 -0700 Subject: [PATCH 4/6] chore: Fix a build error --- src/write.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/write.rs b/src/write.rs index f753cb83..b6fbf883 100644 --- a/src/write.rs +++ b/src/write.rs @@ -21,7 +21,7 @@ use std::default::Default; use std::fmt::{Debug, Formatter}; use std::io; use std::io::prelude::*; -use std::io::{BufReader, Cursor, SeekFrom}; +use std::io::{BufReader, SeekFrom}; use std::marker::PhantomData; use std::mem; use std::str::{from_utf8, Utf8Error}; @@ -884,7 +884,7 @@ impl ZipWriter { // Add an extra field to the extra_data, per APPNOTE 4.6.11 let mut pad_body = vec![0; pad_length - 4]; if pad_body.len() >= 2 { - Cursor::new(&mut pad_body).write_u16_le(options.alignment)?; + pad_body[0..2].copy_from_slice(&options.alignment.to_le_bytes()); } writer.write_u16_le(0xa11e)?; writer From 2a131e67a9a7e82348f8ee19799932962dd34f40 Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Sun, 2 Jun 2024 17:29:49 -0700 Subject: [PATCH 5/6] fix: Use deflate-flate2 flag to guard import --- examples/write_dir.rs | 6 +++--- src/read.rs | 6 +----- src/write.rs | 24 ++++-------------------- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/examples/write_dir.rs b/examples/write_dir.rs index 5475f7bc..5fe41dc8 100644 --- a/examples/write_dir.rs +++ b/examples/write_dir.rs @@ -42,12 +42,12 @@ fn real_main() -> i32 { let method = match args.compression_method { CompressionMethod::Stored => zip::CompressionMethod::Stored, CompressionMethod::Deflated => { - #[cfg(not(feature = "deflate"))] + #[cfg(not(feature = "deflate-flate2"))] { - println!("The `deflate` feature is not enabled"); + println!("The `deflate-flate2` feature is not enabled"); return 1; } - #[cfg(feature = "deflate")] + #[cfg(feature = "deflate-flate2")] zip::CompressionMethod::Deflated } CompressionMethod::DeflatedZlib => { diff --git a/src/read.rs b/src/read.rs index 94ed2366..15c1319e 100644 --- a/src/read.rs +++ b/src/read.rs @@ -24,11 +24,7 @@ use std::ops::Deref; use std::path::{Path, PathBuf}; use std::sync::{Arc, OnceLock}; -#[cfg(any( - feature = "deflate", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" -))] +#[cfg(feature = "deflate-flate2")] use flate2::read::DeflateDecoder; #[cfg(feature = "deflate64")] diff --git a/src/write.rs b/src/write.rs index b6fbf883..2b10f634 100644 --- a/src/write.rs +++ b/src/write.rs @@ -27,11 +27,7 @@ use std::mem; use std::str::{from_utf8, Utf8Error}; use std::sync::Arc; -#[cfg(any( - feature = "deflate", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" -))] +#[cfg(feature = "deflate-flate2")] use flate2::{write::DeflateEncoder, Compression}; #[cfg(feature = "bzip2")] @@ -1569,11 +1565,7 @@ impl GenericZipWriter { } } - #[cfg(any( - feature = "deflate", - feature = "deflate-zlib", - feature = "deflate-zlib-ng", - ))] + #[cfg(feature = "deflate-flate2")] { Ok(Box::new(move |bare| { GenericZipWriter::Deflater(DeflateEncoder::new( @@ -1633,11 +1625,7 @@ impl GenericZipWriter { fn switch_to(&mut self, make_new_self: SwitchWriterFunction) -> ZipResult<()> { let bare = match mem::replace(self, Closed) { Storer(w) => w, - #[cfg(any( - feature = "deflate", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" - ))] + #[cfg(feature = "deflate-flate2")] GenericZipWriter::Deflater(w) => w.finish()?, #[cfg(feature = "deflate-zopfli")] GenericZipWriter::ZopfliDeflater(w) => w.finish()?, @@ -1665,11 +1653,7 @@ impl GenericZipWriter { fn ref_mut(&mut self) -> Option<&mut dyn Write> { match self { Storer(ref mut w) => Some(w as &mut dyn Write), - #[cfg(any( - feature = "deflate", - feature = "deflate-zlib", - feature = "deflate-zlib-ng" - ))] + #[cfg(feature = "deflate-flate2")] GenericZipWriter::Deflater(ref mut w) => Some(w as &mut dyn Write), #[cfg(feature = "deflate-zopfli")] GenericZipWriter::ZopfliDeflater(w) => Some(w as &mut dyn Write), From 28fb992532eca55ddb736a44c84d4f0ca2ecfb4d Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Sun, 2 Jun 2024 17:37:45 -0700 Subject: [PATCH 6/6] chore: Refactor alignment field write logic --- src/write.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/write.rs b/src/write.rs index 2b10f634..151258a8 100644 --- a/src/write.rs +++ b/src/write.rs @@ -880,7 +880,7 @@ impl ZipWriter { // Add an extra field to the extra_data, per APPNOTE 4.6.11 let mut pad_body = vec![0; pad_length - 4]; if pad_body.len() >= 2 { - pad_body[0..2].copy_from_slice(&options.alignment.to_le_bytes()); + [pad_body[0], pad_body[1]] = options.alignment.to_le_bytes(); } writer.write_u16_le(0xa11e)?; writer