-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzz_test.go
68 lines (61 loc) · 1.34 KB
/
fuzz_test.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
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
//go:build go1.18
// +build go1.18
package picobuf_test
import (
"testing"
"storj.io/picobuf"
"storj.io/picobuf/internal/picotest"
)
func FuzzDecode(f *testing.F) {
x, err := picobuf.Marshal(&picotest.AllTypes{
Int32: 1,
Int64: 1,
Uint32: 1,
Uint64: 1,
Sint32: 1,
Sint64: 1,
Fixed32: 1,
Fixed64: 1,
Sfixed32: 1,
Sfixed64: 1,
Float: 1,
Double: 1,
Bool: true,
String_: "hello",
Bytes: []byte{0x1, 0x2},
Message: &picotest.Message{Int32: 1},
Int32S: []int32{1, 2},
Int64S: []int64{1, 2},
Uint32S: []uint32{1, 2},
Uint64S: []uint64{1, 2},
Sint32S: []int32{1, 2},
Sint64S: []int64{1, 2},
Fixed32S: []uint32{1, 2},
Fixed64S: []uint64{1, 2},
Sfixed32S: []int32{1, 2},
Sfixed64S: []int64{1, 2},
Floats: []float32{1, 2},
Doubles: []float64{1, 2},
Bools: []bool{true, true},
Strings: []string{"hello", "world"},
Bytess: [][]byte{{1}, {2}},
Messages: []*picotest.Message{{Int32: 1}, {Int32: 2}},
})
if err != nil {
f.Fatal(err)
}
f.Add(x)
f.Fuzz(func(t *testing.T, data []byte) {
var z picotest.AllTypes
err := picobuf.Unmarshal(data, &z)
if err != nil {
return
}
_, err = picobuf.Marshal(&z)
if err != nil {
t.Fatal(err)
}
})
}