-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcrashers_test.go
More file actions
46 lines (38 loc) · 1014 Bytes
/
crashers_test.go
File metadata and controls
46 lines (38 loc) · 1014 Bytes
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
package protobuf
import (
"testing"
"github.com/stretchr/testify/assert"
)
// These are from fuzz.go, which found these problems.
type t1 [32]byte
type t2 struct {
X, Y t1
Sl []bool
T3 t3
T3s [3]t3
}
type t3 struct {
I int
F float64
B bool
}
func TestCrash1(t *testing.T) {
in := []byte("*\x00")
// Found this former crasher while looking for the reason for
// the next one.
var i uint32
err := Decode(in, &i)
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "not a struct")
var s t2
err = Decode(in, &s)
assert.NotNil(t, err)
assert.Equal(t, "Error while decoding field {Name:T3s PkgPath: Type:[3]protobuf.t3 Tag: Offset:112 Index:[4] Anonymous:false}: append to non-slice", err.Error())
}
func TestCrash2(t *testing.T) {
in := []byte("\n\x00")
var s t2
err := Decode(in, &s)
assert.NotNil(t, err)
assert.Equal(t, "Error while decoding field {Name:X PkgPath: Type:protobuf.t1 Tag: Offset:0 Index:[0] Anonymous:false}: array length and buffer length differ", err.Error())
}