Skip to content

Commit 1149baf

Browse files
authored
attribute: fix go-fuzz crasher (#7)
1 parent 5847c34 commit 1149baf

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

attribute.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ func (a *Attribute) UnmarshalBinary(b []byte) error {
5050
return errInvalidAttribute
5151
}
5252

53-
if a.Length == 0 {
53+
switch {
54+
// No length, no data
55+
case a.Length == 0:
5456
a.Data = make([]byte, 0)
55-
}
56-
if a.Length > 0 {
57+
// Not enough length for any data
58+
case a.Length < 4:
59+
return errInvalidAttribute
60+
// Data present
61+
case a.Length >= 4:
5762
a.Data = make([]byte, len(b[4:a.Length]))
5863
copy(a.Data, b[4:a.Length])
5964
}

attribute_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ func TestUnmarshalAttributes(t *testing.T) {
248248
},
249249
err: errInvalidAttribute,
250250
},
251+
{
252+
name: "fuzz crasher: length 1, too short",
253+
b: []byte("\x01\x0000"),
254+
err: errInvalidAttribute,
255+
},
251256
{
252257
name: "no attributes, length 0",
253258
b: []byte{

0 commit comments

Comments
 (0)