Skip to content

Commit

Permalink
modification to support gcp in test
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Reddy <[email protected]>
  • Loading branch information
Vivek Reddy committed Oct 11, 2024
1 parent 43c8f76 commit 0e986a7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/testenv/gcputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -390,6 +391,15 @@ func untarFile(src, dest string) error {

for {
header, err := tarReader.Next()
if err != nil {
return err
}

// Sanitize the file path to prevent Zip Slip
targetPath := filepath.Join(dest, header.Name)
if !strings.HasPrefix(targetPath, filepath.Clean(dest)+string(os.PathSeparator)) {
return fmt.Errorf("invalid file path: %s", targetPath)
}

if err == io.EOF {
break // End of archive
Expand All @@ -398,7 +408,7 @@ func untarFile(src, dest string) error {
return err
}

targetPath := filepath.Join(dest, header.Name)
targetPath = filepath.Join(dest, header.Name)

switch header.Typeflag {
case tar.TypeDir:
Expand Down

0 comments on commit 0e986a7

Please sign in to comment.