1
0
mirror of https://github.com/golang/go synced 2024-11-24 21:00:09 -07:00

fix read the big zip error

fix read the big zip error
This commit is contained in:
Alanthur 2024-10-14 18:00:15 +08:00 committed by GitHub
parent b521ebb55a
commit eab1f0d436
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -565,10 +565,10 @@ func readDataDescriptor(r io.Reader, f *File) error {
} }
func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, baseOffset int64, err error) { func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, baseOffset int64, err error) {
// look for directoryEndSignature in the last 1k, then in the last 65k // look for directoryEndSignature in the last 1k, then in the last 65k, then in the last 5M
var buf []byte var buf []byte
var directoryEndOffset int64 var directoryEndOffset int64
for i, bLen := range []int64{1024, 65 * 1024} { for i, bLen := range []int64{1024, 65 * 1024,5*1024*1024} {
if bLen > size { if bLen > size {
bLen = size bLen = size
} }
@ -581,7 +581,7 @@ func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, baseOffset
directoryEndOffset = size - bLen + int64(p) directoryEndOffset = size - bLen + int64(p)
break break
} }
if i == 1 || bLen == size { if i == 2 || bLen == size {
return nil, 0, ErrFormat return nil, 0, ErrFormat
} }
} }