test(fuzz): Fix bugs that were breaking the fuzz test

This commit is contained in:
Chris Hennick 2024-05-06 14:41:51 -07:00
parent 447f9c6e4f
commit 162c9b7281
No known key found for this signature in database
GPG key ID: DA47AABA4961C509
2 changed files with 14 additions and 14 deletions

View file

@ -19,7 +19,10 @@ pub enum BasicFileOperation<'k> {
}, },
ShallowCopy(Box<FileOperation<'k>>), ShallowCopy(Box<FileOperation<'k>>),
DeepCopy(Box<FileOperation<'k>>), DeepCopy(Box<FileOperation<'k>>),
MergeWithOtherFile(Box<[FileOperation<'k>]>) MergeWithOtherFile {
first: Box<FileOperation<'k>>,
rest: Box<[FileOperation<'k>]>
}
} }
#[derive(Arbitrary, Clone, Debug)] #[derive(Arbitrary, Clone, Debug)]
@ -85,13 +88,14 @@ where
do_operation(writer, &base, false, flush_on_finish_file)?; do_operation(writer, &base, false, flush_on_finish_file)?;
writer.deep_copy_file_from_path(&base.path, &path)?; 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())); 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( let _ = do_operation(
&mut other_writer, &mut other_writer,
&operation, &operation,
abort, false,
false, false,
); );
}); });

View file

@ -329,14 +329,10 @@ impl<R> ZipArchive<R> {
reader: R, reader: R,
central_start: u64, central_start: u64,
) -> ZipResult<Self> { ) -> ZipResult<Self> {
if files.is_empty() { let initial_offset = match files.first() {
return Err(ZipError::InvalidArchive( Some((_, file)) => file.header_start,
"attempt to finalize empty zip writer into readable", None => 0,
)); };
}
/* This is where the whole file starts. */
let (_, first_header) = files.first().unwrap();
let initial_offset = first_header.header_start;
let shared = Arc::new(zip_archive::Shared { let shared = Arc::new(zip_archive::Shared {
files, files,
offset: initial_offset, offset: initial_offset,
@ -368,10 +364,10 @@ impl<R: Read + Seek> ZipArchive<R> {
&mut self, &mut self,
mut w: W, mut w: W,
) -> ZipResult<IndexMap<Box<str>, ZipFileData>> { ) -> ZipResult<IndexMap<Box<str>, ZipFileData>> {
let mut new_files = self.shared.files.clone(); if self.shared.files.is_empty() {
if new_files.is_empty() {
return Ok(IndexMap::new()); 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 /* 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 * enforce that, and executable zips like PEX files will have a shebang line so will
* definitely be greater than 0. * definitely be greater than 0.