Skip to content

Commit

Permalink
Merge branch 'main' into mal_target
Browse files Browse the repository at this point in the history
  • Loading branch information
tstromberg committed Oct 2, 2024
2 parents fa1233d + 19e37ec commit 5684e05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cmd/mal/mal.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func main() {
mc.OCI = true
case c.String("image") == "" && !c.Bool("processes"):
cmdArgs := c.Args().Slice()
mc.ScanPaths = []string{cmdArgs[0]}
mc.ScanPaths = cmdArgs
case c.Bool("processes"):
mc.Processes = true
}
Expand Down Expand Up @@ -454,7 +454,7 @@ func main() {
mc.OCI = true
case c.String("image") == "" && !c.Bool("processes"):
cmdArgs := c.Args().Slice()
mc.ScanPaths = []string{cmdArgs[0]}
mc.ScanPaths = cmdArgs
case c.Bool("processes"):
mc.Processes = true
}
Expand Down
18 changes: 11 additions & 7 deletions pkg/action/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package action
import (
"archive/tar"
"archive/zip"
"compress/bzip2"
"compress/gzip"
"context"
"errors"
Expand Down Expand Up @@ -37,6 +38,11 @@ func extractTar(ctx context.Context, d string, f string) error {
return fmt.Errorf("failed to open file: %w", err)
}
defer tf.Close()
// Set offset to the file origin regardless of type
_, err = tf.Seek(0, io.SeekStart)
if err != nil {
return fmt.Errorf("failed to seek to start: %w", err)
}

var tr *tar.Reader

Expand All @@ -49,17 +55,15 @@ func extractTar(ctx context.Context, d string, f string) error {
defer gzStream.Close()
tr = tar.NewReader(gzStream)
case strings.Contains(filename, ".xz"):
_, err := tf.Seek(0, io.SeekStart) // Seek to start for xz reading
if err != nil {
return fmt.Errorf("failed to seek to start: %w", err)
}
xzStream, err := xz.NewReader(tf)
if err != nil {
return fmt.Errorf("failed to create xz reader: %w", err)
}
tr = tar.NewReader(xzStream)
case strings.Contains(filename, ".bz2") || strings.Contains(filename, ".bzip2"):
br := bzip2.NewReader(tf)
tr = tar.NewReader(br)
default:
_, err := tf.Seek(0, io.SeekStart) // Seek to start for tar reading
if err != nil {
return fmt.Errorf("failed to seek to start: %w", err)
}
Expand All @@ -68,7 +72,7 @@ func extractTar(ctx context.Context, d string, f string) error {

for {
header, err := tr.Next()
if errors.Is(err, io.EOF) {
if errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF) {
break
}
if err != nil {
Expand Down Expand Up @@ -350,7 +354,7 @@ func extractionMethod(ext string) func(context.Context, string, string) error {
return extractZip
case ".gz":
return extractGzip
case ".apk", ".gem", ".tar", ".tar.gz", ".tgz", ".tar.xz", ".xz":
case ".apk", ".bz2", ".bzip2", ".gem", ".tar", ".tar.gz", ".tgz", ".tar.xz", ".xz":
return extractTar
default:
return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/action/programkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (

var archiveMap = map[string]bool{
".apk": true,
".bz2": true,
".bzip2": true,
".gem": true,
".gz": true,
".jar": true,
Expand Down

0 comments on commit 5684e05

Please sign in to comment.