Limit Zopfli iterations in write fuzzing

This commit is contained in:
Chris Hennick 2023-05-28 10:11:51 -07:00
parent 26eeabe488
commit d9c20c55c4
No known key found for this signature in database
GPG key ID: 25653935CC8B6C74
2 changed files with 8 additions and 2 deletions

View file

@ -54,7 +54,8 @@ fn do_operation<T>(writer: &mut RefCell<zip_next::ZipWriter<T>>,
let name = operation.name;
match operation.basic {
BasicFileOperation::WriteNormalFile {contents, mut options, ..} => {
if contents.iter().map(Vec::len).sum::<usize>() >= u32::MAX as usize {
let uncompressed_size = contents.iter().map(Vec::len).sum::<usize>();
if uncompressed_size >= u32::MAX as usize {
options = options.large_file(true);
}
writer.borrow_mut().start_file(name, options)?;

View file

@ -170,7 +170,7 @@ impl arbitrary::Arbitrary<'_> for FileOptions {
match options.compression_method {
Deflated => {
if bool::arbitrary(u)? {
let level = u.int_in_range(0..=265)?;
let level = u.int_in_range(0..=24)?;
options.compression_level = Some(level);
#[cfg(feature = "deflate-zopfli")]
if level > Compression::best().level().try_into().unwrap() {
@ -334,6 +334,11 @@ impl FileOptions {
self.zopfli_buffer_size = size;
self
}
/// Returns the compression level currently set.
pub fn get_compression_level(&self) -> Option<i32> {
self.compression_level
}
}
impl Default for FileOptions {