Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added internal/zip/fixtures/myproject.zip
Binary file not shown.
8 changes: 6 additions & 2 deletions pkg/cmd/run/download/zip.go → internal/zip/zip.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package download
package zip

import (
"archive/zip"
Expand All @@ -17,7 +17,11 @@ const (
execMode os.FileMode = 0755
)

func extractZip(zr *zip.Reader, destDir safepaths.Absolute) error {
// ExtractZip extracts the contents of a zip archive to destDir.
// Files that would result in path traversal are silently skipped.
// Files that would produce any other error cause the extraction to be aborted,
// and the error is returned.
func ExtractZip(zr *zip.Reader, destDir safepaths.Absolute) error {
for _, zf := range zr.File {
fpath, err := destDir.Join(zf.Name)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/run/download/zip_test.go → internal/zip/zip_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package download
package zip

import (
"archive/zip"
Expand All @@ -19,7 +19,7 @@ func Test_extractZip(t *testing.T) {
require.NoError(t, err)
defer zipFile.Close()

err = extractZip(&zipFile.Reader, extractPath)
err = ExtractZip(&zipFile.Reader, extractPath)
require.NoError(t, err)

_, err = os.Stat(filepath.Join(extractPath.String(), "src", "main.go"))
Expand Down
Loading