Skip to content

int overflow in requestN for Responder#146

Merged
stevegury merged 1 commit intorsocket:masterfrom
NiteshKant:req-n
Jul 14, 2016
Merged

int overflow in requestN for Responder#146
stevegury merged 1 commit intorsocket:masterfrom
NiteshKant:req-n

Conversation

@NiteshKant
Copy link
Copy Markdown
Contributor

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.

#### 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`.
@NiteshKant NiteshKant added this to the 0.2.2 milestone Jul 13, 2016
// 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)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it back, ReactiveSocket protocol defines the request-n as a 32bits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is an integer value. So this is ready to merge then?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is.

@stevegury stevegury merged commit 1cf1e64 into rsocket:master Jul 14, 2016
@NiteshKant NiteshKant deleted the req-n branch October 26, 2016 17:07
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.

2 participants