-
Notifications
You must be signed in to change notification settings - Fork 84
fix: Need to include zip64 extra field in central directory #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Pr0methean
wants to merge
4
commits into
master
Choose a base branch
from
fix_353_missing_cde_zip64
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a8ddc33
fix: Need to include zip64 extra field in central directory
Pr0methean 320f6f2
test: Fix an issue where some tests passed even without the fix
Pr0methean 55fcdc6
Merge branch 'master' into fix_353_missing_cde_zip64
Pr0methean fb9c555
Merge branch 'master' into fix_353_missing_cde_zip64
Pr0methean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
use std::{fs::File, io::Write}; | ||
use tempfile::tempdir; | ||
use zip::{write::SimpleFileOptions, ZipWriter}; | ||
|
||
fn write_data(w: &mut dyn Write, size: usize) { | ||
let chunks = 1 << 20; // 1MB chunks | ||
let mut written = 0; | ||
let buf = vec![0x21; chunks]; | ||
while written < size { | ||
let to_write = (size - written).min(chunks); | ||
w.write_all(&buf[..to_write]).unwrap(); | ||
written += to_write; | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_append_near_4gb() { | ||
let dir = tempdir().unwrap(); | ||
let path = dir.path().join("large-then-small.zip"); | ||
|
||
// Create a new zip file with a large file close to 4GB | ||
{ | ||
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 just under 4GB (4GB - 1 byte) | ||
let size = u32::MAX; | ||
write_data(&mut writer, size as usize); | ||
|
||
// Add a small file | ||
writer.start_file_from_path("small_file", opts).unwrap(); | ||
write_data(&mut writer, 1024); | ||
|
||
writer.finish().unwrap(); | ||
} | ||
|
||
// Now append to the zip file | ||
{ | ||
let file = File::options().read(true).write(true).open(&path).unwrap(); | ||
let mut writer = ZipWriter::new_append(file).unwrap(); | ||
|
||
let opts = SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored); | ||
|
||
// Add another small file | ||
writer.start_file_from_path("appended_file", opts).unwrap(); | ||
write_data(&mut writer, 1024); | ||
|
||
writer.finish().unwrap(); | ||
} | ||
|
||
// Verify the zip file is valid by reading it | ||
{ | ||
let file = File::open(&path).unwrap(); | ||
let mut archive = zip::ZipArchive::new(file).unwrap(); | ||
|
||
assert_eq!(archive.len(), 3); | ||
assert!(!archive.has_overlapping_files().unwrap()); | ||
assert!(archive.file_names().any(|name| name == "close_to_4gb")); | ||
assert!(archive.file_names().any(|name| name == "small_file")); | ||
assert!(archive.file_names().any(|name| name == "appended_file")); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_append_near_4gb_with_1gb_files() { | ||
let dir = tempdir().unwrap(); | ||
let path = dir.path().join("large-then-small.zip"); | ||
|
||
// Create a new zip file with 4 files totaling 1GB | ||
{ | ||
let file = File::create(&path).unwrap(); | ||
let mut writer = ZipWriter::new(file); | ||
|
||
let opts = SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored); | ||
|
||
for i in 0..=3 { | ||
writer | ||
.start_file_from_path(format!("close_to_4gb_{i}"), opts) | ||
.unwrap(); | ||
|
||
// Write a file that's 1 GB | ||
let size = 1u64 << 30; | ||
write_data(&mut writer, size as usize); | ||
} | ||
|
||
// Add a small file | ||
writer.start_file_from_path("small_file", opts).unwrap(); | ||
write_data(&mut writer, 1024); | ||
|
||
writer.finish().unwrap(); | ||
} | ||
|
||
// Now append to the zip file | ||
{ | ||
let file = File::options().read(true).write(true).open(&path).unwrap(); | ||
let mut writer = ZipWriter::new_append(file).unwrap(); | ||
|
||
let opts = SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored); | ||
|
||
// Add another small file | ||
writer.start_file_from_path("appended_file", opts).unwrap(); | ||
write_data(&mut writer, 1024); | ||
|
||
writer.finish().unwrap(); | ||
} | ||
|
||
// Verify the zip file is valid by reading it | ||
{ | ||
let file = File::open(&path).unwrap(); | ||
let mut archive = zip::ZipArchive::new(file).unwrap(); | ||
|
||
assert_eq!(archive.len(), 6); | ||
assert!(!archive.has_overlapping_files().unwrap()); | ||
assert!(archive.file_names().any(|name| name == "close_to_4gb_0")); | ||
assert!(archive.file_names().any(|name| name == "close_to_4gb_1")); | ||
assert!(archive.file_names().any(|name| name == "close_to_4gb_2")); | ||
assert!(archive.file_names().any(|name| name == "close_to_4gb_3")); | ||
assert!(archive.file_names().any(|name| name == "small_file")); | ||
assert!(archive.file_names().any(|name| name == "appended_file")); | ||
} | ||
} | ||
|
||
// A smaller test that doesn't create a 4GB file but still tests the logic | ||
#[test] | ||
fn test_append_with_large_file_flag() { | ||
let dir = tempdir().unwrap(); | ||
let path = dir.path().join("test.zip"); | ||
|
||
// Create a new zip file | ||
{ | ||
let file = File::create(&path).unwrap(); | ||
let mut writer = ZipWriter::new(file); | ||
|
||
let opts = SimpleFileOptions::default() | ||
.compression_method(zip::CompressionMethod::Stored) | ||
.large_file(true); // Force ZIP64 format | ||
|
||
writer.start_file_from_path("file1", opts).unwrap(); | ||
write_data(&mut writer, 1024); | ||
|
||
writer.finish().unwrap(); | ||
} | ||
|
||
// Now append to the zip file | ||
{ | ||
let file = File::options().read(true).write(true).open(&path).unwrap(); | ||
let mut writer = ZipWriter::new_append(file).unwrap(); | ||
|
||
let opts = SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored); | ||
|
||
// Add another file | ||
writer.start_file_from_path("file2", opts).unwrap(); | ||
write_data(&mut writer, 1024); | ||
|
||
writer.finish().unwrap(); | ||
} | ||
|
||
// Verify the zip file is valid by reading it | ||
{ | ||
let file = File::open(&path).unwrap(); | ||
let archive = zip::ZipArchive::new(file).unwrap(); | ||
|
||
assert_eq!(archive.len(), 2); | ||
assert!(archive.file_names().any(|name| name == "file1")); | ||
assert!(archive.file_names().any(|name| name == "file2")); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.