Skip to content
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

Other programs report incorrect CRCs when the large_file(true) is used to write zip members #195

Open
Tim-Evans-Seequent opened this issue Jun 18, 2024 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Tim-Evans-Seequent
Copy link

Tim-Evans-Seequent commented Jun 18, 2024

Describe the bug
When writing a zip file, if I used .large_file(true) the file is written with an incorrect CRC. This causes 7-Zip and Windows Explorer at least to fail to extract the zip. CRC errors are also shown by unzip -t from the command line.

The problem does not occur with .large_file(false).

To Reproduce
Steps to reproduce the behaviour:

  1. Build and run this code to create test.zip:
use std::{fs::File, io::Write};
use zip::write::{SimpleFileOptions, ZipWriter};

fn main() {
  let file = File::create("test.zip").unwrap();
  let mut zip = ZipWriter::new(file);
  let options = SimpleFileOptions::default()
      .compression_method(zip::CompressionMethod::Stored)
      .large_file(true);
  zip.start_file("hello_world.txt", options).unwrap();
  zip.write(b"Hello\nWorld!").unwrap();
  zip.finish().unwrap();
}
  1. Run unzip -t test.zip from the command line. It will show these errors:
$ unzip -t test.zip
Archive:  test.zip
  testing: hello_world.txt          bad CRC d7daaffa  (should be 77e47a71)
At least one error was detected in test.zip.
  1. Try to extract test.zip using 7-Zip. It will show these errors:
1   C:\Work\experiments\rust\zip_test\test.zip
    Unexpected end of data
2   CRC failed : hello_world.txt
  1. Try to "Extract All.." the file within Windows Explorer. It will fail with error 0x80004005: Unspecified error on hello_world.txt.

Note that this all works without errors if .large_file(true) is removed. The file reads correctly using the zip crate itself, which might indicate problems with the reader as well.

Expected behavior
The zip file should not produce errors with unzip -t and should open and extract correctly with other programs. Maybe tests should be added to check files with unzip -t to avoid this type of error in the future.

Screenshots
The Window Explorer error:
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Crate version: 2.1.3
@Tim-Evans-Seequent Tim-Evans-Seequent added the bug Something isn't working label Jun 18, 2024
@Tim-Evans-Seequent
Copy link
Author

Checking older versions, I have found that the bug is in v2.1.0 but not v2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants