What version of Go are you using (go version)?
Looking at git master (currently d85a353 of writer.go)
Description
There seems to be an error in archive/zip/writer.go when creating a zip64 extra field when the local header offset is less than UINT32_MAX (e.g. for the first file in the central directory).
https://github.com/golang/go/blob/master/src/archive/zip/writer.go#L114 writes the 64-bit offset of the local header to the zip64 extra field even if the 32-bit offset written at https://github.com/golang/go/blob/master/src/archive/zip/writer.go#L129 isn't equal to 0xFFFFFFFF.
According to APPNOTE.TXT, this isn't allowed as per:
The order of the fields in the zip64 extended
information record is fixed, but the fields MUST
only appear if the corresponding Local or Central
directory record field is set to 0xFFFF or 0xFFFFFFFF.
While Info-ZIP and other implementations may not care about extraneous fields, Microsoft's implementation explodes accordingly at https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/IO/Zip/ZipIOExtraFieldZip64Element.cs,120 because it won't expect the field by this logic https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/IO/Zip/ZipIOCentralDirectoryFileHeader.cs,92
Proposed solution
Change https://github.com/golang/go/blob/master/src/archive/zip/writer.go#L126 to say:
if h.isZip64() || h.offset > uint32max {
instead of
if h.offset > uint32max {
to mimic the logic some lines above that decides when to write the zip64 extra field at all.
This seems to be the minimal change to fix the issue, otherwise the extra field might need to vary in size.
P.S. thanks to archive/zip authors for providing a readable reference
What version of Go are you using (
go version)?Looking at git master (currently d85a353 of writer.go)
Description
There seems to be an error in archive/zip/writer.go when creating a zip64 extra field when the local header offset is less than UINT32_MAX (e.g. for the first file in the central directory).
https://github.com/golang/go/blob/master/src/archive/zip/writer.go#L114 writes the 64-bit offset of the local header to the zip64 extra field even if the 32-bit offset written at https://github.com/golang/go/blob/master/src/archive/zip/writer.go#L129 isn't equal to 0xFFFFFFFF.
According to APPNOTE.TXT, this isn't allowed as per:
While Info-ZIP and other implementations may not care about extraneous fields, Microsoft's implementation explodes accordingly at https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/IO/Zip/ZipIOExtraFieldZip64Element.cs,120 because it won't expect the field by this logic https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/IO/Zip/ZipIOCentralDirectoryFileHeader.cs,92
Proposed solution
Change https://github.com/golang/go/blob/master/src/archive/zip/writer.go#L126 to say:
instead of
to mimic the logic some lines above that decides when to write the zip64 extra field at all.
This seems to be the minimal change to fix the issue, otherwise the extra field might need to vary in size.
P.S. thanks to archive/zip authors for providing a readable reference