Skip to content

Commit

Permalink
fix: Some date/time filters were previously unreliable (i.e. later-pa…
Browse files Browse the repository at this point in the history
…ss filters had no earliest-pass or latest-fail, and vice-versa)
  • Loading branch information
Pr0methean committed Jun 4, 2024
1 parent cb50ca1 commit b7bec1c
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 1915 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: windows-latest, msrv

unresolved import `crate::write::EncryptWith::Aes`

Check failure on line 1915 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

unresolved import `crate::write::EncryptWith::Aes`

Check failure on line 1915 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

unresolved import `crate::write::EncryptWith::Aes`
use crate::write::SimpleFileOptions;
use crate::CompressionMethod::Stored;
use crate::ZipArchive;
use crate::CompressionMethod::{Deflated, Stored};

Check failure on line 1917 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: windows-latest, msrv

unresolved import `crate::CompressionMethod::Deflated`

Check failure on line 1917 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

unresolved import `crate::CompressionMethod::Deflated`

Check failure on line 1917 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

unresolved import `crate::CompressionMethod::Deflated`
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() {
Expand Down Expand Up @@ -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),

Check failure on line 2513 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: windows-latest, msrv

struct `FileOptions<'_, ExtendedFileOptions>` has no field named `zopfli_buffer_size`

Check failure on line 2513 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

struct `write::FileOptions<'_, write::ExtendedFileOptions>` has no field named `zopfli_buffer_size`

Check failure on line 2513 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

struct `write::FileOptions<'_, write::ExtendedFileOptions>` has no field named `zopfli_buffer_size`
};
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(())
}
}

0 comments on commit b7bec1c

Please sign in to comment.