From 50573f9d9136b1a5e8efeda86eaa54c618834bda Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 31 Jan 2023 10:48:48 -0500 Subject: [PATCH 1/3] zip: fix compression of files larger than 4GB --- src/archive/zip.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 05af45daa..c3ce44b29 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -219,10 +219,16 @@ where options }; - let mut file = fs::File::open(entry.path())?; + let mut file = fs::File::open(path)?; + let large = file.metadata().map_or( + true, + |metadata| metadata.len() > 0xffffffff, // 4 GB + ); writer.start_file( path.to_str().unwrap(), - options.last_modified_time(get_last_modified_time(&file)), + options + .large_file(large) + .last_modified_time(get_last_modified_time(&file)), )?; io::copy(&mut file, &mut writer)?; } From bc79cad9c6b2a70f83e7a2b581b9a274860be673 Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 31 Jan 2023 10:51:11 -0500 Subject: [PATCH 2/3] add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e058e618c..f66398793 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ Categories Used: - Multi-threaded compression for gzip and snappy using gzp [\#348](https://github.com/ouch-org/ouch/pull/348) ([figsoda](https://github.com/figsoda)) +### Bug Fixes + +- Fix decompression of zip archives with files larger than 4GB [\#354](https://github.com/ouch-org/ouch/pull/354) ([figsoda](https://github.com/figsoda)) + ## [0.4.1](https://github.com/ouch-org/ouch/compare/0.4.0...0.4.1) ### New Features From 58da7dbf34b3b9dca5acb68fe86214f5a8f2008f Mon Sep 17 00:00:00 2001 From: figsoda Date: Tue, 31 Jan 2023 18:42:32 -0500 Subject: [PATCH 3/3] always use zip64 --- src/archive/zip.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/archive/zip.rs b/src/archive/zip.rs index c3ce44b29..fa0ab18f2 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -145,7 +145,9 @@ where W: Write + Seek, { let mut writer = zip::ZipWriter::new(writer); - let options = zip::write::FileOptions::default(); + // always use ZIP64 to allow compression of files larger than 4GB + // the format is widely supported and the extra 20B is negligible in most cases + let options = zip::write::FileOptions::default().large_file(true); let output_handle = Handle::from_path(output_path); #[cfg(not(unix))] @@ -220,15 +222,9 @@ where }; let mut file = fs::File::open(path)?; - let large = file.metadata().map_or( - true, - |metadata| metadata.len() > 0xffffffff, // 4 GB - ); writer.start_file( path.to_str().unwrap(), - options - .large_file(large) - .last_modified_time(get_last_modified_time(&file)), + options.last_modified_time(get_last_modified_time(&file)), )?; io::copy(&mut file, &mut writer)?; }