Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (

const (
defaultBufSize = 4096

// maxBodyLength bounds the FIX BodyLength tag 9 that the parser will accept.
// A crafted value near the maximum integer overflows the message framing
// arithmetic and drives a negative slice index, and a merely large value
// forces the read buffer to grow without bound. This ceiling is far above
// any real FIX message so valid traffic is unaffected.
maxBodyLength = 100 * 1024 * 1024
)

type parser struct {
Expand Down Expand Up @@ -136,6 +143,10 @@ func (p *parser) jumpLength() (int, error) {
return length, errors.New("Invalid length")
}

if length > maxBodyLength {
return length, errors.New("Invalid length")
}

return offset + length, nil
}

Expand Down
14 changes: 14 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ func (s *ParserSuite) TestOverflowLength() {
s.NotNil(err)
}

func (s *ParserSuite) TestMaxIntLength() {
stream := "8=FIX.4.2\x019=9223372036854775807\x0135=A\x0110=000\x01"
s.reader = strings.NewReader(stream)
_, err := s.ReadMessage()
s.NotNil(err)
}

func (s *ParserSuite) TestOversizedLength() {
stream := "8=FIX.4.2\x019=209715200\x0135=A\x0110=000\x01"
s.reader = strings.NewReader(stream)
_, err := s.ReadMessage()
s.NotNil(err)
}

func (s *ParserSuite) TestJumpLength() {
stream := "8=FIXT.1.19=11135=D34=449=TW52=20140511-23:10:3456=ISLD11=ID21=340=154=155=INTC60=20140511-23:10:3410=2348=FIXT.1.19=9535=D34=549=TW52=20140511-23:10:3456=ISLD11=ID21=340=154=155=INTC60=20140511-23:10:3410=198"

Expand Down
Loading