Repository navigation
Reject out of range FIX BodyLength that overflows the parser and causes a panic - #804
Open
quantova-inc wants to merge 1 commit into
Open
quantova-inc wants to merge 1 commit into
quantova-inc wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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.