From b7bec1c2dd42470de4f0aedcb1131d72ad8f1d72 Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Mon, 3 Jun 2024 22:35:40 -0700 Subject: [PATCH] fix: Some date/time filters were previously unreliable (i.e. later-pass filters had no earliest-pass or latest-fail, and vice-versa) --- src/write.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/write.rs b/src/write.rs index f6791f2d..5da1da72 100644 --- a/src/write.rs +++ b/src/write.rs @@ -1908,16 +1908,18 @@ const EXTRA_FIELD_MAPPING: [u16; 49] = [ #[cfg(test)] mod test { - use super::{FileOptions, ZipWriter}; + use super::{ExtendedFileOptions, FileOptions, ZipWriter}; use crate::compression::CompressionMethod; use crate::result::ZipResult; use crate::types::DateTime; + use crate::write::EncryptWith::Aes; use crate::write::SimpleFileOptions; - use crate::CompressionMethod::Stored; - use crate::ZipArchive; + use crate::CompressionMethod::{Deflated, Stored}; + use crate::{AesMode, ZipArchive}; use std::io; use std::io::{Cursor, Read, Write}; use std::path::PathBuf; + use std::sync::Arc; #[test] fn write_empty_zip() { @@ -2488,4 +2490,61 @@ mod test { let _ = ZipArchive::new(first_writer.finish()?)?; Ok(()) } + + #[test] + fn test_fuzz_failure_2024_06_04() -> ZipResult<()> { + let mut writer = ZipWriter::new(Cursor::new(Vec::new())); + writer.set_flush_on_finish_file(false); + let options = FileOptions { + compression_method: Deflated, + compression_level: Some(20), + last_modified_time: DateTime::from_date_and_time(2107, 4, 8, 7, 0, 19)?, + permissions: Some(4281355088), + large_file: false, + encrypt_with: Some(Aes { + mode: AesMode::Aes128, + password: "", + }), + extended_options: ExtendedFileOptions { + extra_data: Arc::new(vec![]), + central_extra_data: Arc::new(vec![]), + }, + alignment: 14335, + zopfli_buffer_size: Some(9223372036854775808), + }; + writer.start_file_from_path("", options)?; + writer.write_all(&[46])?; + writer.write_all(&[])?; + writer.write_all(&[41, 0])?; + writer.write_all(&[255, 255, 46])?; + writer.write_all(&[])?; + writer.write_all(&[41, 0])?; + writer.write_all(&[255, 7])?; + writer.write_all(&[80, 255])?; + writer.write_all(&[6, 255])?; + writer.write_all(&[41, 255, 246, 255, 255, 255])?; + writer.write_all(&[255, 7])?; + writer.write_all(&[255])?; + writer.write_all(&[255, 7])?; + writer.write_all(&[80, 255])?; + writer.write_all(&[255, 45])?; + writer.write_all(&[56, 255, 0, 255, 56, 195, 255, 7])?; + writer.write_all(&[80, 255])?; + writer.write_all(&[246, 255, 255, 255, 7])?; + writer.write_all(&[80, 255, 255])?; + writer.write_all(&[255, 7])?; + writer.write_all(&[80, 255])?; + writer.write_all(&[255])?; + writer.write_all( + &[ + 56, 195, 255, 7, 80, 255, 246, 255, 255, 255, 7, 80, 255, 6, 255, 255, 0, 255, 80, + 255, 7, 80, 255, 44, 255, 246, 255, 255, 255, 7, 80, 255, 255, 56, 195, 255, 7, 80, + 255, 246, 255, 255, 255, 7, 80, 255, 255, 255, 7, 2, 75, 255, 56, 195, 255, 7, 80, + 255, 246, 255, 255, 255, 7, 80, 255, 6, 255, 41, 255, 255, 7, 80, 255, 255, 45, 52, + 255, 0, 255, 255, 0, 255, 80, 255, 246, + ] + )?; + writer.finish_into_readable()?; + Ok(()) + } }