Skip to content

Commit f0459d0

Browse files
committed
Add parser and runtime fuzz targets
1 parent 5a9f8e8 commit f0459d0

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ Goal: improve day-to-day developer productivity and interpreter robustness.
329329
- [ ] Profile evaluator hotspots and optimize dispatch paths.
330330
- [ ] Reduce allocations in common value transformations.
331331
- [ ] Improve error rendering for deeply nested call stacks.
332-
- [ ] Add fuzz tests for parser and runtime edge cases.
332+
- [x] Add fuzz tests for parser and runtime edge cases.
333333

334334
### CI and Release Engineering
335335

vibes/fuzz_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package vibes
2+
3+
import (
4+
"context"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func FuzzCompileScriptDoesNotPanic(f *testing.F) {
10+
f.Add([]byte(""))
11+
f.Add([]byte("def run() 1 end"))
12+
f.Add([]byte("def broken("))
13+
f.Add([]byte("begin\n raise(\"boom\")\nrescue\n 1\nend"))
14+
f.Add([]byte("require(\"../path\")"))
15+
16+
f.Fuzz(func(t *testing.T, raw []byte) {
17+
engine := MustNewEngine(Config{})
18+
_, _ = engine.Compile(string(raw))
19+
})
20+
}
21+
22+
func FuzzRuntimeEdgeCasesDoNotPanic(f *testing.F) {
23+
engine := MustNewEngine(Config{})
24+
script, err := engine.Compile(`
25+
def run(text, pattern)
26+
stable_groups = text.split("").group_by_stable do |char|
27+
if char == ""
28+
:empty
29+
else
30+
:present
31+
end
32+
end
33+
34+
{
35+
match: Regex.match(pattern, text),
36+
replace_all: Regex.replace_all(text, pattern, "x"),
37+
json: JSON.stringify({ text: text }),
38+
template: "value={{text}}".template({ text: text }),
39+
chunks: text.split("").chunk(4),
40+
windows: text.split("").window(2),
41+
stable_groups: stable_groups
42+
}
43+
end
44+
`)
45+
if err != nil {
46+
f.Fatalf("compile failed: %v", err)
47+
}
48+
49+
f.Add("", "a*")
50+
f.Add("ID-12 ID-34", "ID-[0-9]+")
51+
f.Add(strings.Repeat("a", 256), "(")
52+
f.Add(" hello \n world ", "\\s+")
53+
f.Add("{}", ".*")
54+
55+
f.Fuzz(func(t *testing.T, text string, pattern string) {
56+
if len(text) > 4096 {
57+
text = text[:4096]
58+
}
59+
if len(pattern) > 1024 {
60+
pattern = pattern[:1024]
61+
}
62+
_, _ = script.Call(context.Background(), "run", []Value{
63+
NewString(text),
64+
NewString(pattern),
65+
}, CallOptions{})
66+
})
67+
}

0 commit comments

Comments
 (0)