File tree 2 files changed +13
-3
lines changed
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -50,10 +50,15 @@ func (a *Attribute) UnmarshalBinary(b []byte) error {
50
50
return errInvalidAttribute
51
51
}
52
52
53
- if a .Length == 0 {
53
+ switch {
54
+ // No length, no data
55
+ case a .Length == 0 :
54
56
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 :
57
62
a .Data = make ([]byte , len (b [4 :a .Length ]))
58
63
copy (a .Data , b [4 :a .Length ])
59
64
}
Original file line number Diff line number Diff line change @@ -248,6 +248,11 @@ func TestUnmarshalAttributes(t *testing.T) {
248
248
},
249
249
err : errInvalidAttribute ,
250
250
},
251
+ {
252
+ name : "fuzz crasher: length 1, too short" ,
253
+ b : []byte ("\x01 \x00 00" ),
254
+ err : errInvalidAttribute ,
255
+ },
251
256
{
252
257
name : "no attributes, length 0" ,
253
258
b : []byte {
You can’t perform that action at this time.
0 commit comments