Make large files more likely

This commit is contained in:
Chris Hennick 2023-05-01 12:29:25 -07:00
parent a23e3889e2
commit 6582e13fc4
No known key found for this signature in database
GPG key ID: 25653935CC8B6C74

View file

@ -2,20 +2,29 @@
use libfuzzer_sys::fuzz_target; use libfuzzer_sys::fuzz_target;
use arbitrary::Arbitrary; use arbitrary::Arbitrary;
use std::fmt::{Debug, Formatter};
use std::io::{Cursor, Read, Seek, Write}; use std::io::{Cursor, Read, Seek, Write};
#[derive(Arbitrary,Debug)]
pub struct ExtraData {
pub header_id: u16,
pub data: Vec<u8>
}
#[derive(Arbitrary,Debug)] #[derive(Arbitrary,Debug)]
pub struct File { pub struct File {
pub name: String, pub name: String,
pub contents: Vec<Vec<u8>>, pub contents: Vec<Vec<u8>>
pub local_extra_data: Vec<ExtraData>, }
pub central_extra_data: Vec<ExtraData>
#[derive(Arbitrary)]
pub struct LargeFile {
pub name: String,
pub large_contents: [u8; u32::MAX as usize + 1],
pub extra_contents: Vec<Vec<u8>>
}
impl Debug for LargeFile {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LargeFile")
.field("name", &self.name)
.field("extra_contents", &self.extra_contents)
.finish()
}
} }
#[derive(Arbitrary,Debug)] #[derive(Arbitrary,Debug)]
@ -24,6 +33,10 @@ pub enum FileOperation {
file: File, file: File,
options: zip_next::write::FileOptions options: zip_next::write::FileOptions
}, },
WriteLarge {
file: LargeFile,
options: zip_next::write::FileOptions
},
ShallowCopy { ShallowCopy {
base: Box<FileOperation>, base: Box<FileOperation>,
new_name: String new_name: String
@ -38,6 +51,7 @@ impl FileOperation {
pub fn get_name(&self) -> String { pub fn get_name(&self) -> String {
match self { match self {
FileOperation::Write {file, ..} => &file.name, FileOperation::Write {file, ..} => &file.name,
FileOperation::WriteLarge {file, ..} => &file.name,
FileOperation::ShallowCopy {new_name, ..} => new_name, FileOperation::ShallowCopy {new_name, ..} => new_name,
FileOperation::DeepCopy {new_name, ..} => new_name FileOperation::DeepCopy {new_name, ..} => new_name
}.to_owned() }.to_owned()
@ -57,6 +71,14 @@ fn do_operation<T>(writer: &mut zip_next::ZipWriter<T>,
writer.write_all(chunk.as_slice())?; writer.write_all(chunk.as_slice())?;
} }
} }
FileOperation::WriteLarge {file, mut options} => {
options = options.large_file(true);
writer.start_file(file.name.to_owned(), options)?;
writer.write_all(&file.large_contents)?;
for chunk in &file.extra_contents {
writer.write_all(chunk.as_slice())?;
}
}
FileOperation::ShallowCopy {base, new_name} => { FileOperation::ShallowCopy {base, new_name} => {
do_operation(writer, base)?; do_operation(writer, base)?;
writer.shallow_copy_file(&base.get_name(), new_name)?; writer.shallow_copy_file(&base.get_name(), new_name)?;