From 390ffd7a42a0b518c6b155ee6e495f2679ce241f Mon Sep 17 00:00:00 2001 From: glikis Date: Sat, 19 Mar 2022 19:45:16 +0200 Subject: [PATCH] - Files larger than MaximumFileSize are now processed, but contents is empty. --- core/match.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/match.go b/core/match.go index 9be78e6..7310a57 100644 --- a/core/match.go +++ b/core/match.go @@ -15,10 +15,19 @@ type MatchFile struct { } func NewMatchFile(path string) MatchFile { + maxFileSize := *session.Options.MaximumFileSize * 1024 path = filepath.ToSlash(path) _, filename := filepath.Split(path) extension := filepath.Ext(path) - contents, _ := ioutil.ReadFile(path) + + var contents []byte + fi, err := os.Stat(path) + if err == nil { + size := fi.Size() + if size < int64(maxFileSize) { + contents, _ = ioutil.ReadFile(path) + } + } return MatchFile{ Path: path, @@ -63,10 +72,9 @@ func (match MatchFile) CanCheckEntropy() bool { func GetMatchingFiles(dir string) []MatchFile { fileList := make([]MatchFile, 0) - maxFileSize := *session.Options.MaximumFileSize * 1024 filepath.Walk(dir, func(path string, f os.FileInfo, err error) error { - if err != nil || f.IsDir() || uint(f.Size()) > maxFileSize || IsSkippableFile(path) { + if err != nil || f.IsDir() || IsSkippableFile(path) { return nil } fileList = append(fileList, NewMatchFile(path))