Skip to content

Commit a57f9b5

Browse files
committed
Fix int overflow in parser
A maliciously crafted message with a bogus body length could make the parser panic if the body length is close to the int limit. Fixes #678 Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
1 parent 2ed31c3 commit a57f9b5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

parser.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ func (p *parser) jumpLength() (int, error) {
132132
return length, err
133133
}
134134

135-
if length <= 0 {
135+
// Issue 678: if length approaches the int limit, it might overflow when
136+
// adding offset and make it negative so we also need to check that
137+
// offset+length is not negative.
138+
if length <= 0 || offset+length <= 0 {
136139
return length, errors.New("Invalid length")
137140
}
138141

parser_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,14 @@ func (s *ParserSuite) TestReadMessageGrowBuffer() {
186186
s.Equal(tc.expectedBufferLen, len(s.parser.buffer))
187187
}
188188
}
189+
190+
// https://github.com/quickfixgo/quickfix/issues/678
191+
func TestIssue678(t *testing.T) {
192+
defer func() {
193+
if err := recover(); err != nil {
194+
t.Error(err)
195+
}
196+
}()
197+
parser := newParser(strings.NewReader(string("8=\x019=119999999999999999999999999999999999999999999999999999999999970\x01")))
198+
_, _ = parser.ReadMessage()
199+
}

0 commit comments

Comments
 (0)