-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathfuzz.go
69 lines (53 loc) · 1.11 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// +build gofuzz
package tsz
import (
"encoding/binary"
"fmt"
"math"
"github.com/dgryski/go-tsz/testdata"
)
func Fuzz(data []byte) int {
fuzzUnpack(data)
if len(data) < 9 {
return 0
}
t0 := uint32(1456236677)
v := float64(10000)
var vals []testdata.Point
s := New(t0)
t := t0
for len(data) >= 10 {
tdelta := uint32(binary.LittleEndian.Uint16(data))
if t == t0 {
tdelta &= (1 << 14) - 1
}
t += tdelta
data = data[2:]
v += float64(int16(binary.LittleEndian.Uint16(data))) + float64(binary.LittleEndian.Uint16(data[2:]))/float64(math.MaxUint16)
data = data[8:]
vals = append(vals, testdata.Point{V: v, T: t})
s.Push(t, v)
}
it := s.Iter()
var i int
for it.Next() {
gt, gv := it.Values()
if gt != vals[i].T || (gv != vals[i].V || math.IsNaN(gv) && math.IsNaN(vals[i].V)) {
panic(fmt.Sprintf("failure: gt=%v vals[i].T=%v gv=%v vals[i].V=%v", gt, vals[i].T, gv, vals[i].V))
}
i++
}
if i != len(vals) {
panic("extra data")
}
return 1
}
func fuzzUnpack(data []byte) {
it, err := NewIterator(data)
if err != nil {
return
}
for it.Next() {
_, _ = it.Values()
}
}