Skip to content

Commit

Permalink
SLK-0000
Browse files Browse the repository at this point in the history
  • Loading branch information
jyothi kumar committed Oct 18, 2024
1 parent c06f467 commit e3b0c0c
Show file tree
Hide file tree
Showing 23 changed files with 413 additions and 64 deletions.
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/language/dotnet/nuget/nuget.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nuget
import (
"context"
"errors"
"github.com/aquasecurity/trivy/pkg/log"
"io"
"io/fs"
"os"
Expand Down Expand Up @@ -104,7 +105,12 @@ func (a *nugetLibraryAnalyzer) PostAnalyze(_ context.Context, input analyzer.Pos
}, nil
}

func (a *nugetLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a *nugetLibraryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("NUGET")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("nuget").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
return slices.Contains(requiredFiles, fileName)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/fanal/analyzer/language/golang/binary/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package binary
import (
"context"
"errors"
"github.com/aquasecurity/trivy/pkg/log"
"os"

"golang.org/x/xerrors"
Expand Down Expand Up @@ -35,6 +36,11 @@ func (a gobinaryLibraryAnalyzer) Analyze(_ context.Context, input analyzer.Analy
}

func (a gobinaryLibraryAnalyzer) Required(_ string, fileInfo os.FileInfo) bool {
others := os.Getenv("GOLANG_BINARY")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("golang oss binary").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
return utils.IsExecutable(fileInfo)
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/fanal/analyzer/language/golang/mod/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ func (a *gomodAnalyzer) PostAnalyze(_ context.Context, input analyzer.PostAnalys
}, nil
}

func (a *gomodAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a *gomodAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("GOLANG_MOD")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("golang oss binary").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
return slices.Contains(requiredFiles, fileName)
}
Expand Down
42 changes: 42 additions & 0 deletions ...a/pkg/mod/github.com/aquasecurity/[email protected]/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/aquasecurity/go-pep440-version v0.0.0-20210121094942-22b2f8951d46/go.mod h1:olhPNdiiAAMiSujemd1O/sc6GcyePr23f/6uGKtthNg=
github.com/aquasecurity/go-version v0.0.0-20210121072130-637058cfe492/go.mod h1:9Beu8XsUNNfzml7WBf3QmyPToP1wm1Gj/Vc5UJKqTzU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/liamg/jfather v0.0.7/go.mod h1:xXBGiBoiZ6tmHhfy5Jzw8sugzajwYdi6VosIpB3/cPM=
github.com/microsoft/go-rustaudit v0.0.0-20220808201409-204dfee52032/go.mod h1:vYT9HE7WCvL64iVeZylKmCsWKfE+JZ8105iuh2Trk8g=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
42 changes: 42 additions & 0 deletions ...a/pkg/mod/github.com/aquasecurity/[email protected]/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/aquasecurity/go-pep440-version v0.0.0-20210121094942-22b2f8951d46/go.mod h1:olhPNdiiAAMiSujemd1O/sc6GcyePr23f/6uGKtthNg=
github.com/aquasecurity/go-version v0.0.0-20210121072130-637058cfe492/go.mod h1:9Beu8XsUNNfzml7WBf3QmyPToP1wm1Gj/Vc5UJKqTzU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/liamg/jfather v0.0.7/go.mod h1:xXBGiBoiZ6tmHhfy5Jzw8sugzajwYdi6VosIpB3/cPM=
github.com/microsoft/go-rustaudit v0.0.0-20220808201409-204dfee52032/go.mod h1:vYT9HE7WCvL64iVeZylKmCsWKfE+JZ8105iuh2Trk8g=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
golang.org/x/exp v0.0.0-20220407100705-7b9b53b0aca4/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/language/java/pom/pom.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pom

import (
"context"
"github.com/aquasecurity/trivy/pkg/log"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -43,7 +44,12 @@ func (a pomAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*
return res, nil
}

func (a pomAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a pomAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("JAVA_POM")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("java pom oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
return filepath.Base(filePath) == types.MavenPom
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/fanal/analyzer/language/nodejs/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ func (a npmLibraryAnalyzer) PostAnalyze(_ context.Context, input analyzer.PostAn
}, nil
}

func (a npmLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a npmLibraryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("NPM")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
// Don't save package-lock.json from the `node_modules` directory to avoid duplication and mistakes.
if fileName == types.NpmPkgLock && !xpath.Contains(filePath, "node_modules") {
Expand Down
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/language/nodejs/pkg/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pkg

import (
"context"
"github.com/aquasecurity/trivy/pkg/log"
"os"
"path/filepath"

Expand Down Expand Up @@ -46,7 +47,12 @@ func (a nodePkgLibraryAnalyzer) Analyze(_ context.Context, input analyzer.Analys
return language.AnalyzePackage(types.NodePkg, input.FilePath, input.Content, &parser{}, input.Options.FileChecksum)
}

func (a nodePkgLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a nodePkgLibraryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("NPM_PKG")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
return requiredFile == filepath.Base(filePath)
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/language/nodejs/pnpm/pnpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pnpm

import (
"context"
"github.com/aquasecurity/trivy/pkg/log"
"os"
"path/filepath"

Expand Down Expand Up @@ -32,7 +33,12 @@ func (a pnpmLibraryAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisI
return res, nil
}

func (a pnpmLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a pnpmLibraryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("NPM_PNPM")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
return utils.StringInSlice(fileName, requiredFiles)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/fanal/analyzer/language/nodejs/yarn/yarn.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ func (a yarnAnalyzer) PostAnalyze(_ context.Context, input analyzer.PostAnalysis
}, nil
}

func (a yarnAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a yarnAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
dirs, fileName := splitPath(filePath)

others := os.Getenv("NPM_YARN")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
if fileName == types.YarnLock &&
// skipping yarn.lock in cache folders
lo.Some(dirs, []string{
Expand Down
7 changes: 6 additions & 1 deletion pkg/fanal/analyzer/language/php/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ func (a composerAnalyzer) PostAnalyze(_ context.Context, input analyzer.PostAnal
}, nil
}

func (a composerAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a composerAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("PHP")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
if !slices.Contains(requiredFiles, fileName) {
return false
Expand Down
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/language/python/pip/pip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pip

import (
"context"
"github.com/aquasecurity/trivy/pkg/log"
"os"
"path/filepath"

Expand Down Expand Up @@ -29,7 +30,12 @@ func (a pipLibraryAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisIn
return res, nil
}

func (a pipLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a pipLibraryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("PYTHON")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
return fileName == types.PipRequirements
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/language/python/pipenv/pipenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pipenv

import (
"context"
"github.com/aquasecurity/trivy/pkg/log"
"os"
"path/filepath"

Expand Down Expand Up @@ -32,7 +33,12 @@ func (a pipenvLibraryAnalyzer) Analyze(_ context.Context, input analyzer.Analysi
return res, nil
}

func (a pipenvLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a pipenvLibraryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("PYTHON")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
return utils.StringInSlice(fileName, requiredFiles)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/fanal/analyzer/language/python/poetry/poetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ func (a poetryAnalyzer) PostAnalyze(_ context.Context, input analyzer.PostAnalys
}, nil
}

func (a poetryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a poetryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("PYTHON")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
return fileName == types.PoetryLock || fileName == types.PyProject
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/language/ruby/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bundler

import (
"context"
"github.com/aquasecurity/trivy/pkg/log"
"os"
"path/filepath"

Expand Down Expand Up @@ -29,7 +30,12 @@ func (a bundlerLibraryAnalyzer) Analyze(_ context.Context, input analyzer.Analys
return res, nil
}

func (a bundlerLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a bundlerLibraryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("RUBY")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
fileName := filepath.Base(filePath)
return fileName == types.GemfileLock
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/language/ruby/gemspec/gemspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gemspec

import (
"context"
"github.com/aquasecurity/trivy/pkg/log"
"os"
"path/filepath"
"regexp"
Expand All @@ -27,7 +28,12 @@ func (a gemspecLibraryAnalyzer) Analyze(_ context.Context, input analyzer.Analys
gemspec.NewParser(), input.Options.FileChecksum)
}

func (a gemspecLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
func (a gemspecLibraryAnalyzer) Required(filePath string, fileInfo os.FileInfo) bool {
others := os.Getenv("RUBY")
if size := fileInfo.Size(); size > 10485760 && others != "" { // 10MB
log.WithPrefix("npm yarn oss").Warn("The size of the scanned file is too large. It is recommended to use `--skip-files` for this file to avoid high memory consumption.", log.Int64("size (MB)", size/1048576))
return false
}
return fileRegex.MatchString(filepath.ToSlash(filePath))
}

Expand Down
Loading

0 comments on commit e3b0c0c

Please sign in to comment.