Repository navigation
Conversation
There was a problem hiding this comment.
Review: reject escaping ZIP member paths
The core change is correct and well-targeted. Gating extraction on filepath.IsLocal(file.Name) is the right primitive for closing the zip-slip hole — Go guarantees that when IsLocal(p) is true, filepath.Join(base, p) stays inside base, so .. traversal, absolute paths, Windows drive-relative/UNC paths, and reserved names are all rejected. Closing the reader returned alongside zip.ErrInsecurePath is a genuine fd-leak fix. Test coverage is strong: it exercises both the custom guard (GODEBUG=zipinsecurepath=1) and the stdlib rejection path (=0), covers Windows-specific vectors behind a runtime.GOOS gate, and asserts the security property (outside file unchanged, outside dir not created) rather than just the error string.
A few non-blocking observations below.
Notes (non-blocking)
- Traversal-guard idiom now diverges from
extractTarGz. After this PR,extractZipusesfilepath.IsLocal, while the siblingextractTarGz(internal/crosscompile/fetch.go:337) still uses the olderstrings.HasPrefix(target, filepath.Clean(dest)+os.PathSeparator)pattern with a different error message (illegal file path). Not a regression, but converging both extractors on thefilepath.IsLocalidiom in a follow-up would remove two parallel hardening patterns from the same file.
Nothing here blocks merge; the inline items are a latent robustness gap and a minor wording nit.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
visualfc
left a comment
There was a problem hiding this comment.
The filepath.IsLocal gate is the right primitive: Go 1.27 still accepts non-local ZIP/TAR names by default, and Join(dest, name) stays inside dest once IsLocal is true. Closing the reader returned with zip.ErrInsecurePath is required on Windows. Creating parent directories covers missing and unordered ZIP directory records.
Tests check the security property (files outside dest are unchanged) for traversal, absolute names, relative destinations, and Windows path forms. CI is green.
A few non-blocking nits below. The .tar.xz path still goes through system tar -xf / 7-Zip; that is outside this PR, but downloadAndExtractArchive uses it for toolchains too.
LLGo baseline benchmarks
String equality benchmarks
Program measurements
Core language and compiler benchmarks
Timer runtime benchmarks
Compared with |
Reject nonlocal TAR/ZIP member names such as
../outside.txtand absolute paths usingfilepath.IsLocal. Create parent directories for ZIP files with missing or unordered directory records, and close readers returned alongsidezip.ErrInsecurePath.Follow up the extraction finding in the review of #2942. Tests cover traversal, relative destinations, Windows path forms and unordered entries. The ZIP traversal regression fails on the previous implementation. The complete
internal/crosscompilesuite passes.