diff --git a/vacation/vacation.go b/vacation/vacation.go index 3d8495f7..bd08113e 100644 --- a/vacation/vacation.go +++ b/vacation/vacation.go @@ -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 @@ -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 { @@ -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():