Skip to content

Commit 5167e5c

Browse files
rolandshoemakergopherbot
authored andcommitted
archive/zip: only consider UncompressedSize when checking dirs
CL 454475 switched from checking CompressedSize to UncompressedSize when determining if we should consider an archive malformed because it contains data and added a test for an example of this (a JAR). We should also remove the hasDataDescriptor check, since that is basically an alias for CompressedSize > 0. The test didn't catch this because we didn't actually attempt to read from the returned reader. Change-Id: Ibc4c1aa9c3a733f3ebf4a956d1e2f8f4900a29cd Reviewed-on: https://go-review.googlesource.com/c/go/+/455523 Run-TryBot: Roland Shoemaker <[email protected]> Reviewed-by: Julie Qiu <[email protected]> Auto-Submit: Roland Shoemaker <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 03bf6f4 commit 5167e5c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/archive/zip/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (f *File) Open() (io.ReadCloser, error) {
237237
// 0. We still want to fail when a directory has associated uncompressed
238238
// data, but we are tolerant of cases where the uncompressed size is
239239
// zero but compressed size is not.
240-
if f.UncompressedSize64 != 0 || f.hasDataDescriptor() {
240+
if f.UncompressedSize64 != 0 {
241241
return &dirReader{ErrFormat}, nil
242242
} else {
243243
return &dirReader{io.EOF}, nil

src/archive/zip/reader_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,9 +1702,12 @@ func TestCompressedDirectory(t *testing.T) {
17021702
t.Fatalf("unexpected error: %v", err)
17031703
}
17041704
for _, f := range r.File {
1705-
_, err = f.Open()
1705+
r, err := f.Open()
17061706
if err != nil {
17071707
t.Fatalf("unexpected error: %v", err)
17081708
}
1709+
if _, err := io.Copy(io.Discard, r); err != nil {
1710+
t.Fatalf("unexpected error: %v", err)
1711+
}
17091712
}
17101713
}

0 commit comments

Comments
 (0)