Skip to content

Reject out of range FIX BodyLength that overflows the parser and causes a panic - #804

Open
quantova-inc wants to merge 1 commit into
quickfixgo:mainfrom
quantova-inc:bound-fix-bodylength
Open

quantova-inc wants to merge 1 commit into
quickfixgo:mainfrom
quantova-inc:bound-fix-bodylength

Conversation

@quantova-inc

Copy link
Copy Markdown

The wire parser reads the FIX BodyLength tag 9 with no upper bound. A peer can send a BodyLength near the maximum integer so that offset plus length overflows to a negative value and the next slice read panics. The parser runs in the per connection read loop so a single crafted message crashes the read goroutine. A merely large BodyLength is also a problem because it forces the read buffer to grow without bound toward the declared size.

This is reachable from any connected peer on both the acceptor and the initiator paths through ReadMessage.

Reproduction

A single message of the form below panics the parser.

8=FIX.4.2\x019=9223372036854775807\x0135=A\x0110=000\x01
runtime error: slice bounds out of range [-9223372036854775778:]

The existing TestOverflowLength only covers a value that wraps to a negative number which the current less than or equal to zero check already rejects. A value that fits in a signed integer yet overflows the offset plus length addition is not covered and it is the one that crashes.

Fix

Bound BodyLength with a ceiling that sits far above any real FIX message so valid traffic is unaffected while both the integer overflow and the unbounded buffer growth are prevented. The message is rejected in jumpLength before any framing arithmetic or buffering.

Tests

Added TestMaxIntLength for the maximum integer case and TestOversizedLength for a large declared length. The full suite passes and gofmt and go vet are clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant