Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #6166 - fix bug in the MessageInputStream byte array read #6170

Merged
merged 1 commit into from
Apr 15, 2021

Conversation

lachlan-roberts
Copy link
Contributor

Issue #6166

The code for MessageInputStream.read(final byte[] b, final int off, final int len) seems to be wrong. Instead of doing ByteBuffer.wrap(b, off, len).flip() we should do something like:

ByteBuffer buffer = ByteBuffer.wrap(b, off, len).slice();
BufferUtil.clear(buffer);
return read(buffer);

This will ensure that the buffer we get to represent the byte array always has a position and limit of 0, an offset of off, and a capacity of len.

The only time when MessageInputStream.read(ByteBuffer) will compact is when the buffer already has content and limit == capacity. So if we make this change, a call to MessageInputStream.read(final byte[] b, final int off, final int len) will never compact as the buffer is always empty with position == limit.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@lachlan-roberts lachlan-roberts requested a review from gregw April 14, 2021 00:55
@lachlan-roberts lachlan-roberts merged commit dab26c6 into jetty-10.0.x Apr 15, 2021
@lachlan-roberts lachlan-roberts deleted the jetty-10.0.x-6166-MessageInputStream branch April 15, 2021 10:16
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.

3 participants