Skip to content

Commit 3203540

Browse files
authored
fuzz: move fuzz_targets from oss-fuzz (#406)
- Moves fuzz_targets from oss-fuzz. This makes it easy to maintain the fuzzers and minimizes breakages that can arise as source code changes over time. - Adds cifuzz action workflow which is a service provided by oss-fuzz where this project already runs, this helps in catching shallow bugs,regression or build breakage by running fuzzers on PR for ~5 minutes.
1 parent 77ce858 commit 3203540

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

.github/workflows/cifuzz.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CIFuzz
2+
on: [pull_request]
3+
jobs:
4+
Fuzzing:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Build Fuzzers
8+
id: build
9+
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
10+
with:
11+
oss-fuzz-project-name: 'burntsushi-toml'
12+
dry-run: false
13+
language: go
14+
- name: Run Fuzzers
15+
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
16+
with:
17+
oss-fuzz-project-name: 'burntsushi-toml'
18+
fuzz-seconds: 300
19+
dry-run: false
20+
language: go
21+
- name: Upload Crash
22+
uses: actions/upload-artifact@v4
23+
if: failure() && steps.build.outcome == 'success'
24+
with:
25+
name: artifacts
26+
path: ./out/artifacts

ossfuzz/fuzz.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ossfuzz
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
7+
"github.com/BurntSushi/toml"
8+
)
9+
10+
func FuzzToml(data []byte) int {
11+
if len(data) >= 2048 {
12+
return 0
13+
}
14+
15+
var v any
16+
_, err := toml.Decode(string(data), &v)
17+
if err != nil {
18+
return 0
19+
}
20+
21+
buf := new(bytes.Buffer)
22+
err = toml.NewEncoder(buf).Encode(v)
23+
if err != nil {
24+
panic(fmt.Sprintf("failed to encode decoded document: %s", err))
25+
}
26+
27+
var v2 any
28+
_, err = toml.Decode(buf.String(), &v2)
29+
if err != nil {
30+
panic(fmt.Sprintf("failed round trip: %s", err))
31+
}
32+
33+
return 1
34+
}

0 commit comments

Comments
 (0)