1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

fix: issue#62: fix ZipSlip bug

This commit is contained in:
dudaodong
2022-11-16 15:08:42 +08:00
parent 81efa800ea
commit be000a4bd6

View File

@@ -8,6 +8,7 @@ import (
"archive/zip"
"bufio"
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
@@ -213,6 +214,8 @@ func Zip(fpath string, destPath string) error {
// UnZip unzip the file and save it to destPath
func UnZip(zipFile string, destPath string) error {
destPath = filepath.Clean(destPath) + string(os.PathSeparator)
zipReader, err := zip.OpenReader(zipFile)
if err != nil {
return err
@@ -221,6 +224,12 @@ func UnZip(zipFile string, destPath string) error {
for _, f := range zipReader.File {
path := filepath.Join(destPath, f.Name)
//issue#62: fix ZipSlip bug
if !strings.HasPrefix(path, destPath) {
return fmt.Errorf("%s: illegal file path", path)
}
if f.FileInfo().IsDir() {
os.MkdirAll(path, os.ModePerm)
} else {