Skip to content

Commit

Permalink
Scan file descriptors rather than files per go-yara docs (chainguard-…
Browse files Browse the repository at this point in the history
…dev#406)

Signed-off-by: egibs <[email protected]>
  • Loading branch information
egibs authored Aug 16, 2024
1 parent 84d44d4 commit a8fb43d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/action/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ func scanSinglePath(ctx context.Context, c bincapz.Config, yrs *yara.Rules, path
}

logger.Debug("calling YARA ScanFile")
if err := yrs.ScanFile(path, 0, 0, &mrs); err != nil {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
fd := f.Fd()
if err := yrs.ScanFileDescriptor(fd, 0, 0, &mrs); err != nil {
logger.Info("skipping", slog.Any("error", err))
return &bincapz.FileReport{Path: path, Error: fmt.Sprintf("scanfile: %v", err)}, nil
}
Expand Down

0 comments on commit a8fb43d

Please sign in to comment.