Fix zip64 reader when file size is < 4GB and 32 bit fields are -1
When CopyFrom writes a zipentry, it strips extra fields and generates data descriptors. When writing data descriptors, it only writes 64 bit values if the relevant sizes are >4GB. In some cases, the sizes are <4GB but 32 bit sizes are set to -1. In this situation, CopyFrom will write incorrect local file header, resulting in a zip file that can't be parsed by standard zip tools. Test: Unit Tests Bug: 161922066 Change-Id: I64319a80647013eaf7693cf8bf5c6120016913a3
This commit is contained in:
parent
ea3574b5fa
commit
45e2f1405d
|
@ -43,6 +43,15 @@ func (w *Writer) CopyFrom(orig *File, newName string) error {
|
|||
offset: uint64(w.cw.count),
|
||||
}
|
||||
w.dir = append(w.dir, h)
|
||||
if !fh.isZip64() {
|
||||
// Some writers will generate 64 bit sizes and set 32 bit fields to
|
||||
// uint32max even if the actual size fits in 32 bit. So we should
|
||||
// make sure CompressedSize contains the correct value in such
|
||||
// cases. With out the two lines below we would be writing invalid(-1)
|
||||
// sizes in such case.
|
||||
fh.CompressedSize = uint32(fh.CompressedSize64)
|
||||
fh.UncompressedSize = uint32(fh.UncompressedSize64)
|
||||
}
|
||||
|
||||
if err := writeHeader(w.cw, fh); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue