Skip to content

Bounds check the parser against two panics on malformed input - #773

Open
MoJony wants to merge 1 commit into
quickfixgo:mainfrom
MoJony:fix/parse-bounds-checks
Open

Bounds check the parser against two panics on malformed input#773
MoJony wants to merge 1 commit into
quickfixgo:mainfrom
MoJony:fix/parse-bounds-checks

Conversation

@MoJony

@MoJony MoJony commented Aug 14, 2026

Copy link
Copy Markdown

Two shapes a peer can put on the wire panic the parser on the session read goroutine, so a single malformed message takes the session down instead of being rejected.

atoi in fix_int.go indexes d[0] with no length check, so any empty-valued int field the parser reads back panics with index out of range. parseUInt already handled the empty case; atoi did not. Repro: 8=FIX.4.2|9=|35=D|34=2|49=TW|56=ISLD|10=000|.

extractXMLDataField in message.go takes its slice bound straight from XMLDataLen(212) and does endIndex += dataLen + 1 before slicing, with no validation. A large value slices past the buffer, and a large enough one overflows int and slices negative. Repro: 8=FIX.4.2|9=20|35=n|34=2|49=CME|56=OAEAAAN|212=999999999|213=<x/>|10=000|, and the same with 212=9223372036854775807.

Both are now rejected with an error instead. Four table cases added in the existing test-file style, plus an empty-input case on TestFIXInt_Read; each fails with a panic before the patch. make vet, make build-src and make test-ci are clean locally (log/mongo needs a live MongoDB and fails the same way on an unpatched tree).

Fixes the parser half of #678. Found by fuzzing an application built on this library.

atoi indexed d[0] without a length check, so any empty-valued int field
the parser reads back panicked. parseUInt already handled the empty case;
atoi did not.

extractXMLDataField took its slice bound straight from XMLDataLen(212)
with no validation. A large value slices past the buffer and a large
enough one overflows int and slices negative.

Both are reachable from a peer on the session read goroutine.
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