Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix int overflow in parser #694

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ func (p *parser) jumpLength() (int, error) {
return length, err
}

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

Expand Down
11 changes: 11 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,14 @@ func (s *ParserSuite) TestReadMessageGrowBuffer() {
s.Equal(tc.expectedBufferLen, len(s.parser.buffer))
}
}

// https://github.com/quickfixgo/quickfix/issues/678
func TestIssue678(t *testing.T) {
defer func() {
if err := recover(); err != nil {
t.Error(err)
}
}()
parser := newParser(strings.NewReader(string("8=\x019=119999999999999999999999999999999999999999999999999999999999970\x01")))
_, _ = parser.ReadMessage()
}
Loading