Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func Recursive(ctx context.Context, fss []fs.FS) (*yarax.Rules, error) {
return err
}

if ctx.Err() != nil {
return ctx.Err()
}

if d.IsDir() {
return nil
}
Expand Down
14 changes: 13 additions & 1 deletion pkg/compile/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"io/fs"
"regexp"
"slices"
"strings"
"testing"
"testing/fstest"
Expand Down Expand Up @@ -118,6 +119,10 @@ func FuzzRecursiveCompile(f *testing.F) {
return err
}

if len(data) > maxFuzzSize {
return nil
}

f.Add(data)

return nil
Expand Down Expand Up @@ -149,6 +154,13 @@ func FuzzRecursiveCompile(f *testing.F) {
return
}

// Skip inputs containing non-printable-ASCII bytes.
if slices.ContainsFunc(data, func(b byte) bool {
return b > 0x7e || (b < 0x20 && b != '\n' && b != '\r' && b != '\t')
}) {
return
}

// Skip inputs with float literals that crash the YARA-X C library.
if bytes.Contains(data, []byte("condition")) && floatPattern.Match(data) {
return
Expand All @@ -160,7 +172,7 @@ func FuzzRecursiveCompile(f *testing.F) {
},
}

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_, _ = Recursive(ctx, []fs.FS{fsys})
Expand Down