forked from expr-lang/expr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_test.go
More file actions
95 lines (86 loc) · 3.27 KB
/
fuzz_test.go
File metadata and controls
95 lines (86 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package fuzz
import (
_ "embed"
"regexp"
"strings"
"testing"
"github.com/expr-lang/expr"
"github.com/expr-lang/expr/vm"
)
//go:embed fuzz_corpus.txt
var fuzzCorpus string
func FuzzExpr(f *testing.F) {
corpus := strings.Split(strings.TrimSpace(fuzzCorpus), "\n")
for _, s := range corpus {
f.Add(s)
}
skip := []*regexp.Regexp{
regexp.MustCompile(`cannot fetch .* from .*`),
regexp.MustCompile(`cannot get .* from .*`),
regexp.MustCompile(`cannot slice`),
regexp.MustCompile(`slice index out of range`),
regexp.MustCompile(`error parsing regexp`),
regexp.MustCompile(`integer divide by zero`),
regexp.MustCompile(`interface conversion`),
regexp.MustCompile(`invalid argument`),
regexp.MustCompile(`invalid character`),
regexp.MustCompile(`invalid operation`),
regexp.MustCompile(`invalid duration`),
regexp.MustCompile(`time: missing unit in duration`),
regexp.MustCompile(`time: unknown unit .* in duration`),
regexp.MustCompile(`unknown time zone`),
regexp.MustCompile(`invalid location name`),
regexp.MustCompile(`json: unsupported value`),
regexp.MustCompile(`json: unsupported type`),
regexp.MustCompile(`json: cannot unmarshal .* into Go value of type .*`),
regexp.MustCompile(`unexpected end of JSON input`),
regexp.MustCompile(`memory budget exceeded`),
regexp.MustCompile(`using interface \{} as type .*`),
regexp.MustCompile(`reflect.Value.MapIndex: value of type .* is not assignable to type .*`),
regexp.MustCompile(`reflect: Call using .* as type .*`),
regexp.MustCompile(`reflect: cannot use .* as type .* in .*`),
regexp.MustCompile(`reflect: Call with too few input arguments`),
regexp.MustCompile(`invalid number of arguments`),
regexp.MustCompile(`reflect: call of reflect.Value.Call on .* Value`),
regexp.MustCompile(`reflect: call of reflect.Value.Index on map Value`),
regexp.MustCompile(`reflect: call of reflect.Value.Len on .* Value`),
regexp.MustCompile(`reflect: string index out of range`),
regexp.MustCompile(`strings: negative Repeat count`),
regexp.MustCompile(`strings: illegal bytes to escape`),
regexp.MustCompile(`invalid date .*`),
regexp.MustCompile(`parsing time .*`),
regexp.MustCompile(`cannot parse .* as .*`),
regexp.MustCompile(`operator "in" not defined on .*`),
regexp.MustCompile(`cannot sum .*`),
regexp.MustCompile(`index out of range: .* \(array length is .*\)`),
regexp.MustCompile(`reduce of empty array with no initial value`),
regexp.MustCompile(`cannot use <nil> as argument \(type .*\) to call .*`),
regexp.MustCompile(`illegal base64 data at input byte .*`),
regexp.MustCompile(`sort order argument must be a string`),
regexp.MustCompile(`sortBy order argument must be a string`),
regexp.MustCompile(`invalid order .*, expected asc or desc`),
regexp.MustCompile(`unknown order, use asc or desc`),
}
env := NewEnv()
fn := Func()
f.Fuzz(func(t *testing.T, code string) {
if len(code) > 1000 {
t.Skip("too long code")
}
program, err := expr.Compile(code, expr.Env(env), fn)
if err != nil {
t.Skipf("compile error: %s", err)
}
v := vm.VM{MemoryBudget: 500000}
_, err = v.Run(program, env)
if err != nil {
for _, r := range skip {
if r.MatchString(err.Error()) {
t.Skipf("skip error: %s", err)
return
}
}
t.Errorf("%s", err)
}
})
}