zip: prevent extracting files into parent dirs (#5314)

This commit is contained in:
Michael Yang
2024-06-26 21:38:21 -07:00
committed by GitHub
parent 4d311eb731
commit 123a722a6f
3 changed files with 133 additions and 22 deletions

View File

@@ -162,9 +162,6 @@ func tempZipFiles(path string) (string, error) {
}
defer tempfile.Close()
zipfile := zip.NewWriter(tempfile)
defer zipfile.Close()
detectContentType := func(path string) (string, error) {
f, err := os.Open(path)
if err != nil {
@@ -233,6 +230,9 @@ func tempZipFiles(path string) (string, error) {
files = append(files, tks...)
}
zipfile := zip.NewWriter(tempfile)
defer zipfile.Close()
for _, file := range files {
f, err := os.Open(file)
if err != nil {