On Wed, Feb 23, 2022 at 1:46 PM David Karr <davidmichaelk...@gmail.com> wrote: > > A while ago, I wrote a small Go app that reads things from zip files. I > tested it with various zip files (usually Java jar files), and it has always > worked perfectly fine. > > Today I'm looking at another jar file. The Java "jar" command likes it > perfectly fine. I could list the contents and extract all the files. Java had > no particular trouble running with the jar file. > > When I try to call "zip.OpenReader()" on this jar file, it just gives me > ""zip: not a valid zip file"". Well, great. > > I then ran a command to run the same command on every jar file in my home > directory tree, where there are a couple of thousand from various tool > distributions. I counted how many failed with that same error. I found just > the one I already have. > > This jar file is a little over 12mb. Several of the jar files that don't > fail are quite a bit larger than this. Most of the ones that don't fail are > smaller than this. The permissions on this jar are the same as the others. > > I then tried passing this jar file to "unzip". It was able to unzip it, but > it did print this: > > warning [<jar file name>]: 3624 extra bytes at beginning or within > zipfile > (attempting to process anyway) > > I tried this on some of the working jar files, and it didn't print this > warning. > > So, it appears that if anything, this jar file is "nonstandard", but both > unzip and jar have no problem with it, and jar didn't even say there was an > issue with it. The zip package, however, bombs on this with no information. > > I'm going to go to the people who gave me that jar file and ask them how they > produced it, but I think it's clear it's not fatally broken. > > I haven't submitted a bug report for this package yet, as I wanted some > feedback on this first.
The error is zip.ErrFormat. From a quick look at the sources it can be returned if - a file header does not start with the required signature (0x04034b50) - a directory header does not start with the required signature (0x02014b50) - a directory entry is too short to contain the additional information it claims to hold - a directory entry fails to contain the additional information it claims to hold - the directory end signature (0x06054b50) is not found - the offset in the directory is invalid (negative or larger than the file size) There is no especially easy way to find out exactly which one is happening. You could add some print statements to archive/zip/reader.go to narrow it down. I'm not sure what to make of the "3624 extra bytes". Not sure how much this helps. If you can share the zip file, you could open a bug report. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVn%3Dag6t2bLobfT3N%3DVcDqn20RzpF%3DTnn9dXTVHYgJogA%40mail.gmail.com.