Skip to content

Commit

Permalink
chore(internal/utils): moved gzip header containing ".." check above.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 9, 2023
1 parent 9803df6 commit 8f4d92d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/utils/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func ExtractTarGz(gzipStream io.Reader, destDir string, stripPathComponents int)
return nil, err
}

if strings.Contains(header.Name, "..") {
return nil, fmt.Errorf("not allowed relative path in tar archive")
}

strippedName := stripComponents(header.Name, stripPathComponents)

switch header.Typeflag {
Expand All @@ -59,10 +63,6 @@ func ExtractTarGz(gzipStream io.Reader, destDir string, stripPathComponents int)
}
files = append(files, d)
case tar.TypeReg:
if strings.Contains(header.Name, "..") {
return nil, fmt.Errorf("not allowed relative path in tar archive")
}

f := filepath.Join(destDir, strippedName)
outFile, err := os.Create(filepath.Clean(f))
if err != nil {
Expand Down

0 comments on commit 8f4d92d

Please sign in to comment.