Skip to content
Open
8 changes: 6 additions & 2 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,12 @@ impl<W: Write + Seek> ZipWriter<W> {
if file.is_using_data_descriptor() {
file.write_data_descriptor(writer, self.auto_large_file)?;
} else {
file.update_local_file_header(writer, file_name_raw)?;
let res = file.update_local_file_header(writer, file_name_raw);
writer.seek(SeekFrom::Start(file_end))?;
if res.is_err() {
self.writing_to_file = false;
res?;
}
Comment thread
Its-Just-Nans marked this conversation as resolved.
Outdated
}
}
if self.flush_on_finish_file {
Expand Down Expand Up @@ -2434,7 +2438,7 @@ impl ZipFileData {
// self.uncompressed_size = spec::ZIP64_BYTES_THR;
} else {
// check compressed size as well as it can also be slightly larger than uncompressed size
if self.compressed_size > spec::ZIP64_BYTES_THR {
if self.compressed_size >= spec::ZIP64_BYTES_THR {
Comment thread
Its-Just-Nans marked this conversation as resolved.
return Err(ZipError::Io(std::io::Error::other(
"large_file(true) option has not been set",
)));
Expand Down
27 changes: 26 additions & 1 deletion tests/append_near_4gb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ fn write_data(w: &mut dyn std::io::Write, size: usize) {
written += to_write;
}
}
#[test]
fn test_append_4gb_without_large_file() {
use std::fs::File;
use tempfile::tempdir;
use zip::ZipWriter;
use zip::write::SimpleFileOptions;

let dir = tempdir().unwrap();
let path = dir.path().join("debug_large_without_large_file_options.zip");
//let path = std::path::PathBuf::from("debug_large_without_large_file_options.zip");

let file = File::create(&path).unwrap();
let mut writer = ZipWriter::new(file);

let opts = SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);

writer.start_file_from_path("close_to_4gb", opts).unwrap();

// Write a file that's 4GB
let size = u32::MAX;
write_data(&mut writer, size as usize);

// Add a small file
assert!(writer.finish().is_err());
}

/// Only on little endian because we cannot use fs with miri CI
#[cfg(all(target_endian = "little", not(miri)))]
Expand All @@ -33,7 +58,7 @@ fn test_append_near_4gb() {
writer.start_file_from_path("close_to_4gb", opts).unwrap();

// Write a file that's just under 4GB (4GB - 1 byte)
let size = u32::MAX;
let size = u32::MAX - 1;
write_data(&mut writer, size as usize);

// Add a small file
Expand Down
Loading