Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit 3648656

Browse files
ianlancetaylorericchiang
authored andcommitted
jar: support Go 1.19 archive/zip
In Go 1.19 the standard library's archive/zip package will automatically and silently handle a prefixed zip file. The log4jscanner package expects to handle the offset itself. To let log4jscanner work with both Go 1.18 and 1.19, change it to read the offset first, before using the archive/zip package. Tested by running tests with both Go 1.18 and Go tip. Without this change, Go tip fails with --- FAIL: TestAutoMitigateExecutable (0.00s) --- FAIL: TestAutoMitigateExecutable/helloworld-executable (0.00s) rewrite_test.go:247: expected offset for executable testdata/helloworld-executable: got=0 --- FAIL: TestAutoMitigateExecutable/vuln-class-executable (0.00s) rewrite_test.go:247: expected offset for executable testdata/vuln-class-executable: got=0 FAIL FAIL github.com/google/log4jscanner/jar 34.541s
1 parent 7f8e802 commit 3648656

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

jar/jar.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,14 @@ func (o offsetReader) ReadAt(p []byte, off int64) (n int, err error) {
211211
// - https://kevinboone.me/execjava.html
212212
// - https://github.com/golang/go/issues/10464
213213
func NewReader(ra io.ReaderAt, size int64) (zr *zip.Reader, offset int64, err error) {
214-
zr, err = zip.NewReader(ra, size)
215-
if err == nil || !errors.Is(err, zip.ErrFormat) {
216-
return zr, 0, err
217-
}
218214
offset, err = zipfork.ReadZIPOffset(ra, size)
219215
if err != nil {
220216
return nil, 0, err
221217
}
222-
zr, err = zip.NewReader(offsetReader{ra, offset}, size-offset)
218+
if offset > 0 {
219+
ra = offsetReader{ra, offset}
220+
}
221+
zr, err = zip.NewReader(ra, size)
223222
return zr, offset, err
224223
}
225224

0 commit comments

Comments
 (0)