diff --git a/fuzz/fuzz_targets/fuzz_write.rs b/fuzz/fuzz_targets/fuzz_write.rs index f1f74a5e..b3415fbb 100644 --- a/fuzz/fuzz_targets/fuzz_write.rs +++ b/fuzz/fuzz_targets/fuzz_write.rs @@ -19,7 +19,10 @@ pub enum BasicFileOperation<'k> { }, ShallowCopy(Box>), DeepCopy(Box>), - MergeWithOtherFile(Box<[FileOperation<'k>]>) + MergeWithOtherFile { + first: Box>, + rest: Box<[FileOperation<'k>]> + } } #[derive(Arbitrary, Clone, Debug)] @@ -85,13 +88,14 @@ where do_operation(writer, &base, false, flush_on_finish_file)?; writer.deep_copy_file_from_path(&base.path, &path)?; } - BasicFileOperation::MergeWithOtherFile(other_ops) => { + BasicFileOperation::MergeWithOtherFile { first, rest } => { let mut other_writer = zip::ZipWriter::new(Cursor::new(Vec::new())); - other_ops.iter().for_each(|operation| { + let _ = do_operation(&mut other_writer, &first, false, flush_on_finish_file); + rest.iter().for_each(|operation| { let _ = do_operation( &mut other_writer, &operation, - abort, + false, false, ); }); diff --git a/src/read.rs b/src/read.rs index f2bb65af..671f00f8 100644 --- a/src/read.rs +++ b/src/read.rs @@ -329,14 +329,10 @@ impl ZipArchive { reader: R, central_start: u64, ) -> ZipResult { - if files.is_empty() { - return Err(ZipError::InvalidArchive( - "attempt to finalize empty zip writer into readable", - )); - } - /* This is where the whole file starts. */ - let (_, first_header) = files.first().unwrap(); - let initial_offset = first_header.header_start; + let initial_offset = match files.first() { + Some((_, file)) => file.header_start, + None => 0, + }; let shared = Arc::new(zip_archive::Shared { files, offset: initial_offset, @@ -368,10 +364,10 @@ impl ZipArchive { &mut self, mut w: W, ) -> ZipResult, ZipFileData>> { - let mut new_files = self.shared.files.clone(); - if new_files.is_empty() { + if self.shared.files.is_empty() { return Ok(IndexMap::new()); } + let mut new_files = self.shared.files.clone(); /* The first file header will probably start at the beginning of the file, but zip doesn't * enforce that, and executable zips like PEX files will have a shebang line so will * definitely be greater than 0.