File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ func UnmarshalUAST(data []byte) ([]*Node, error) {
69
69
return nil , ErrUnmarshalUAST .New (err )
70
70
}
71
71
72
+ if nodeLen < 1 {
73
+ return nil , ErrUnmarshalUAST .New (fmt .Errorf ("malformed data" ))
74
+ }
75
+
72
76
node := uast .NewNode ()
73
77
nodeBytes := buf .Next (int (nodeLen ))
74
78
if int32 (len (nodeBytes )) != nodeLen {
Original file line number Diff line number Diff line change
1
+ package service_test
2
+
3
+ import (
4
+ "bytes"
5
+ "encoding/binary"
6
+ "testing"
7
+
8
+ "github.com/src-d/gitbase-web/server/service"
9
+ "github.com/stretchr/testify/suite"
10
+ )
11
+
12
+ type UastSuite struct {
13
+ suite.Suite
14
+ }
15
+
16
+ func TestUastSuite (t * testing.T ) {
17
+ s := new (UastSuite )
18
+ suite .Run (t , s )
19
+ }
20
+
21
+ func (suite * UastSuite ) TestNegativeNodeLen () {
22
+ var nodeLen int32 = - 20
23
+
24
+ buf := new (bytes.Buffer )
25
+ err := binary .Write (buf , binary .BigEndian , nodeLen )
26
+ suite .Require ().NoError (err )
27
+
28
+ nodes , err := service .UnmarshalUAST (buf .Bytes ())
29
+ suite .Require ().Error (err )
30
+ suite .Require ().Nil (nodes )
31
+ }
You can’t perform that action at this time.
0 commit comments