Skip to content

Commit

Permalink
refactor(secret): move warning about file size after IsBinary check (
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen authored Jul 9, 2024
1 parent ab0fd0d commit 5a9f1a6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/fanal/analyzer/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (a *SecretAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput
return nil, nil
}

if size := input.Info.Size(); size > 10485760 { // 10MB
log.WithPrefix("secret").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.FilePath(input.FilePath), log.Int64("size (MB)", size/1048576))
}

content, err := io.ReadAll(input.Content)
if err != nil {
return nil, xerrors.Errorf("read error %s: %w", input.FilePath, err)
Expand Down Expand Up @@ -166,9 +170,6 @@ func (a *SecretAnalyzer) Required(filePath string, fi os.FileInfo) bool {
return false
}

if size := fi.Size(); size > 10485760 { // 10MB
log.WithPrefix("secret").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.FilePath(filePath), log.Int64("size (MB)", size/1048576))
}
return true
}

Expand Down

0 comments on commit 5a9f1a6

Please sign in to comment.