Skip to content

Commit

Permalink
Fixes issue with stripping '.' directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt authored and sophiewigmore committed Jun 21, 2021
1 parent 0d429c0 commit 8f4bab3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions vacation/vacation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/ulikunitz/xz"
)

// An Archive decompresses tar, gzip and xz compressed tar, and zip files from
// An Archive decompresses tar, gzip, xz, and bzip2 compressed tar, and zip files from
// an input stream.
type Archive struct {
reader io.Reader
Expand Down Expand Up @@ -107,17 +107,20 @@ func (ta TarArchive) Decompress(destination string) error {
return fmt.Errorf("failed to read tar response: %s", err)
}

// Skip if the destination it the destination directory itself i.e. ./
if hdr.Name == "./" {
// Clean the name in the header to prevent './filename' being stripped to
// 'filename' also to skip if the destination it the destination directory
// itself i.e. './'
var name string
if name = filepath.Clean(hdr.Name); name == "." {
continue
}

err = checkExtractPath(hdr.Name, destination)
err = checkExtractPath(name, destination)
if err != nil {
return err
}

fileNames := strings.Split(hdr.Name, "/")
fileNames := strings.Split(name, "/")

// Checks to see if file should be written when stripping components
if len(fileNames) <= ta.components {
Expand Down Expand Up @@ -386,17 +389,20 @@ func (z ZipArchive) Decompress(destination string) error {
}

for _, f := range zr.File {
// Skip if the destination it the destination directory itself i.e. ./
if f.Name == "./" {
// Clean the name in the header to prevent './filename' being stripped to
// 'filename' also to skip if the destination it the destination directory
// itself i.e. './'
var name string
if name = filepath.Clean(f.Name); name == "." {
continue
}

err = checkExtractPath(f.Name, destination)
err = checkExtractPath(name, destination)
if err != nil {
return err
}

path := filepath.Join(destination, f.Name)
path := filepath.Join(destination, name)

switch {
case f.FileInfo().IsDir():
Expand Down

0 comments on commit 8f4bab3

Please # to comment.