Skip to content

Reject out-of-range and empty integer field values#765

Open
raphaelroshan wants to merge 1 commit into
quickfixgo:mainfrom
raphaelroshan:fix/int-parse-overflow-empty
Open

Reject out-of-range and empty integer field values#765
raphaelroshan wants to merge 1 commit into
quickfixgo:mainfrom
raphaelroshan:fix/int-parse-overflow-empty

Conversation

@raphaelroshan

Copy link
Copy Markdown

Problem

atoi/parseUInt in fix_int.go back FIXInt.Read, which parses integer FIX fields including MsgSeqNum (34), BodyLength (9), and resend-range fields. Two issues:

  1. Silent overflow. parseUInt accumulates n = n*10 + digit with no range check, so an out-of-range value wraps silently and is returned with a nil error:

    • "9223372036854775808" (MaxInt64+1) → -9223372036854775808
    • "18446744073709551617" (MaxUint64+1) → 1
    • "99999999999999999999" → wrapped garbage

    A malformed or oversized field (e.g. tag 34) is therefore accepted with a corrupted value instead of being rejected, which can feed wrong values into sequence-number handling.

  2. Empty-input panic. atoi reads d[0] before checking the length, so an empty integer field value panics with index out of range [0] with length 0.

Fix

  • parseUInt detects overflow before it happens (n > (math.MaxInt-digit)/10) and returns an error.
  • atoi length-checks its input before indexing d[0].

Both keep the allocation-free hot path. Added tests for the overflow and empty-input cases; existing tests and the full package suite pass.

atoi/parseUInt silently overflowed on integer field values that exceed
the int range: e.g. "9223372036854775808" wrapped to a negative number
and "18446744073709551617" to 1, all returned with a nil error. Because
atoi backs FIXInt.Read (MsgSeqNum, BodyLength, resend ranges, etc.), a
malformed or oversized field silently corrupted the parsed value instead
of being rejected.

parseUInt now detects overflow before it happens and returns an error.
atoi also length-checks its input before indexing d[0], which previously
panicked on an empty integer field.

Adds tests for the overflow and empty-input cases.
@raphaelroshan raphaelroshan force-pushed the fix/int-parse-overflow-empty branch from 4b0d094 to 4daa4b5 Compare July 12, 2026 07:26
@raphaelroshan raphaelroshan marked this pull request as ready for review July 12, 2026 07:27
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