-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
archive/zip: Reader.Read returns ErrChecksum on certain files #21876
Comments
I've investigated this issue and extracted both the go and ruby code together with a test to reproduce the issue and a possible fix for the issuers ruby code here: what happensIMO, this is a non-issue from Go's point of view, here is why: I was able to reproduce the issue on "go version go1.11.5 darwin/amd64" with the *.jar file and ruby code provided to this issue. Also, I was able to create a similar zip file using ZIP(1L) on macOS that behaved similarly with the ruby script provided and then processed with the go code of this issue. What seems to be happening is the following:
fixTo fix this issue on the issuers side, general purpose flags can be cleared.
Also (I'm not a ruby expert) Rubyzip's zip output stream might have to be fixed for entries that where copied over from an existing zip file. There is an issue [10] on Rubyzip that is Open and indicates to be similar to Issue21876. Similar to Go's zip reader, macOS's Archive Utility.app cannot open the ZIP file produced by Rubyzip. issue reproducedHere we produce a zip file with data descriptors included for zip file entries using "-fd" flag with ZIP(1L) on macOS. Then, as described in the issue, the ruby script is used to remove directories out of the zip file and the zip file is transformed to a tar file using Go. Run the following script (found here: https://github.com/marcellanz/go-21876) to reproduce the issue:
|
Hi @marcellanz, thank you for your wonderful analysis. It's thorough and seems to conclusively show that the issue is with buggy file generation in Ruby. Given that there is nothing actionable on Go's end, I'm closing the issue. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.7.1 darwin/amd64
Does this issue reproduce with the latest release?
Don't know
What operating system and processor architecture are you using (
go env
)?What did you do?
This is fun.
Create a zip file on Windows, or any other platform where the
directory entries don't have the 'd' bit set. Here's the one we worked on: https://github.com/cloudfoundry/cf-acceptance-tests/blob/master/assets/java-spring/java-spring.jar
Copy bad-win.zip to orig-bad-win.zip, so you can run step 3 repeatedly:
Run the zip file through some ruby code like this:
require 'zip'
def get_dirs_from_zip(zip_path)
Zip::File.open(zip_path) do |in_zip|
in_zip.select(&:directory?)
end
end
dir_list = get_dirs_from_zip(zip_path)
Zip::File.open(zip_file) do |in_zip|
dir_list.each do |dir|
in_zip.remove(dir)
end
end
The go code is attached in a file called transform.go
I ran this command (note that the code wants ok-win.tar to exist in advance):
touch ok-win.tar ; go run transform.go bad-win.zip ok-win.tar
What did you expect to see?
I expected to see a tar file called
ok-win.tar
What did you see instead?
"zip: checksum error"
Notes
There are three likely sources for this error (4 but we're allowing winzip to not set the 'd' bit because zip is weird about directories anyway):
Our ruby code seems ok, because it's not a problem with the zip files where the 'd' bit is set.
The error might be in the ruby zip library, but I can't really report it until I have a better idea
of the cause of the checksum error. I left some printf's in the code, so you can see the error occurs in the call
io.Copy(tarWriter, zipFileReader)
, and not earlier calls that read the zip file.The text was updated successfully, but these errors were encountered: