From 909473caea6298d1c649e3f709fcbaf69b25b146 Mon Sep 17 00:00:00 2001 From: Chris Hennick Date: Thu, 4 May 2023 12:06:23 -0700 Subject: [PATCH] Bug fix --- src/write.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/write.rs b/src/write.rs index 286a2bb1..1590bed4 100644 --- a/src/write.rs +++ b/src/write.rs @@ -316,9 +316,7 @@ impl ZipWriter { let src_data = &self.files[src_index]; let data_start = src_data.data_start.load(); let compressed_size = src_data.compressed_size; - if compressed_size > write_position - data_start { - return Err(ZipError::InvalidArchive("Source file size too large")); - } + debug_assert!(compressed_size <= write_position - data_start); let uncompressed_size = src_data.uncompressed_size; let mut options = FileOptions::default() .large_file(compressed_size.max(uncompressed_size) > spec::ZIP64_BYTES_THR) @@ -346,7 +344,11 @@ impl ZipWriter { self.start_entry(dest_name, options, Some(raw_values))?; self.writing_to_file = true; self.writing_raw = true; - Ok(self.write_all(©)?) + if let Err(e) = self.write_all(©) { + self.abort_file().unwrap(); + return Err(e.into()); + } + self.finish_file() } }