Fix integer/long overflow in content-length parsing, timestamp ordering, and HTTP/2 flow control#1049
Draft
pjfanning wants to merge 5 commits into
Draft
Conversation
23b3014 to
66b3ad5
Compare
Member
Author
|
I think a few of the changes should be non-controversial but the refactor for RFC 7540 §6.9.1 (MaxWindowSize) might be an edge case that we may not want to worry too much about. |
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.
Silent arithmetic overflow in four places can produce incorrect behavior: bogus content-length acceptance, wrong timestamp ordering, and HTTP/2 flow-control windows that wrap instead of triggering the required protocol errors.
ContentLengthParser — positive-wrapping Long overflow
The
result < 0guard only catches overflow that wraps negative. Values like1844674407370955163 * 10wrap to a small positiveLong, silently accepting an invalid content-length. Fixed with a pre-multiply bounds check:Timestamp.Ordering.compare — subtraction overflow
math.signum(x.timestampNanos - y.timestampNanos)overflows when comparing timestamps nearLong.MIN_VALUE/Long.MAX_VALUE(e.g. theneversentinel). Replaced withjava.lang.Long.compare.HTTP/2 flow-control window overflow (RFC 7540 §6.9.1)
A
WINDOW_UPDATEthat pushes a window above2^31 − 1must be treated as a protocol error — connection error (GOAWAY) at the connection level, stream error (RST_STREAM) at the stream level. Previously both windows were incremented unconditionally withIntarithmetic.MaxWindowSize = Int.MaxValueconstant toHttp2ProtocolupdateConnectionLevelWindownow returnsBoolean;Http2DemuxsendsGOAWAY(FLOW_CONTROL_ERROR)onfalseOutStream.increaseWindownow returnsBoolean; all four call paths inHttp2StreamHandling(Sending,Open,OpenReceivingDataFirst,HalfClosedRemoteWaitingForOutgoingStream) sendRST_STREAM(FLOW_CONTROL_ERROR)and transition toClosedon overflowThe overflow check uses a
toLongwidening cast to avoid the very overflow being detected: