Skip to content

Commit

Permalink
Fix directory exploits
Browse files Browse the repository at this point in the history
  • Loading branch information
pomo-mondreganto committed May 22, 2022
1 parent 31da684 commit 385e532
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pkg/archive/targz.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package archive

import (
"archive/tar"
"compress/gzip"
"errors"
"fmt"
"io"
Expand All @@ -9,9 +11,6 @@ import (
"strings"

"github.com/sirupsen/logrus"

"archive/tar"
"compress/gzip"
)

func Untar(dst string, r io.Reader) error {
Expand Down Expand Up @@ -117,11 +116,6 @@ func Tar(src string, w io.Writer) error {
return err
}

// return on non-regular files (thanks to [kumo](https://medium.com/@komuw/just-like-you-did-fbdd7df829d3) for this suggested update)
if !fi.Mode().IsRegular() {
return nil
}

// create a new dir/file header
header, err := tar.FileInfoHeader(fi, fi.Name())
if err != nil {
Expand All @@ -136,6 +130,10 @@ func Tar(src string, w io.Writer) error {
return fmt.Errorf("writing tar heeader: %w", err)
}

if fi.IsDir() {
return nil
}

// open files for taring
f, err := os.Open(file)
if err != nil {
Expand Down

0 comments on commit 385e532

Please sign in to comment.