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

compressed file cannot be extracted or opened by Windows's native zip program if it contains some specific hash sequence #291

Open
J-ZhengLi opened this issue Feb 12, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@J-ZhengLi
Copy link

Describe the bug

I've encounter this strange bug where the compressed file cannot be extracted by Windows if it contains some specific file contents, however 7-zip works fine, probably is Windows being buggy again.
Currently my only option is changing the compress method to Stored, but I'd like to know if this can be fixed here.

To Reproduce

The code creates a zip file with Deflated method, resulting a zip file that cannot be fully extracted on Windows 10 and 11.

let file = std::fs::File::create("hash.zip")?;
let mut zip = zip::ZipWriter::new(file);
let options = SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated);

zip.start_file("abc.txt", options)?;
zip.write_all(b"hello world\n")?;
zip.start_file("abc.sha256", options)?;
zip.write_all(b"abcdef1234567890edae5bb42a3d63129ef5b58157cb2980096f0be23cebccd0  abc.txt")?;
zip.start_file("123.sha256", options)?;
// similar hash, only replacing the first 6 hex digits, but this file can be extracted
zip.write_all(b"1234561234567890edae5bb42a3d63129ef5b58157cb2980096f0be23cebccd0  abc.txt")?;

zip.finish()?;

after creating the hash.zip file, right click it then click extract all. Or, just open the zip file then try to open abc.sha256

Screenshots

Image

Desktop (please complete the following information):

  • OS: Windows 11 IoT Enterprise LTSC
  • Version: 24H2

Additional context

The hash.zip generated by above code if you don't wanna run it: hash.zip

@J-ZhengLi J-ZhengLi added the bug Something isn't working label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant