forked from pion/rtcp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fuzz.go
51 lines (45 loc) · 921 Bytes
/
fuzz.go
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
// +build gofuzz
package rtcp
import (
"bytes"
"io"
)
// Fuzz implements a randomized fuzz test of the rtcp
// parser using go-fuzz.
//
// To run the fuzzer, first download go-fuzz:
// `go get github.com/dvyukov/go-fuzz/...`
//
// Then build the testing package:
// `go-fuzz-build github.com/pion/webrtc`
//
// And run the fuzzer on the corpus:
// ```
// mkdir workdir
//
// # optionally add a starter corpus of valid rtcp packets.
// # the corpus should be as compact and diverse as possible.
// cp -r ~/my-rtcp-packets workdir/corpus
//
// go-fuzz -bin=ase-fuzz.zip -workdir=workdir
// ````
func Fuzz(data []byte) int {
r := NewReader(bytes.NewReader(data))
for {
_, data, err := r.ReadPacket()
if err == io.EOF {
break
}
if err != nil {
return 0
}
packet, err := Unmarshal(data)
if err != nil {
return 0
}
if _, err := packet.Marshal(); err != nil {
return 0
}
}
return 1
}