int overflow in requestN for Responder#146
Merged
stevegury merged 1 commit intorsocket:masterfrom Jul 14, 2016
Merged
Conversation
#### Problem `ReactiveSocket` expects `requestN` to be an `int` whereas `ReactiveStreams` expects it to be a `long`. `Responder` does not correctly convert `long` to `int` for values greater than `Integer.MAX_VALUE`. This sends `-1` as the `requestN` value of the `RequestN` frame. #### Modification If the value is greater than `Integer.MAX_VALUE`, use `Integer.MAX_VALUE` instead. #### Result We will not send invalid values over the wire for `RequestN`.
| // initial requestN back to the requester (subtract 1 | ||
| // for the initial frame which was already sent) | ||
| child.onNext(Frame.RequestN.from(streamId, rn.intValue() - 1)); | ||
| child.onNext(Frame.RequestN.from(streamId, Math.min(Integer.MAX_VALUE, rn.intValue() - 1))); |
Member
There was a problem hiding this comment.
Actually, based on the spec, the request-n is a 64bits value (it should actually be a 63bits, but that's another story).
https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md#request-n-frame
So instead of downcasting everything to int, we upcasting everything to long.
The RequestNFrame is bogus.
Member
There was a problem hiding this comment.
I take it back, ReactiveSocket protocol defines the request-n as a 32bits.
Contributor
Author
There was a problem hiding this comment.
Yes it is an integer value. So this is ready to merge then?
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.
Problem
ReactiveSocketexpectsrequestNto be anintwhereasReactiveStreamsexpects it to be along.Responderdoes not correctly convertlongtointfor values greater thanInteger.MAX_VALUE. This sends-1as therequestNvalue of theRequestNframe.Modification
If the value is greater than
Integer.MAX_VALUE, useInteger.MAX_VALUEinstead.Result
We will not send invalid values over the wire for
RequestN.