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

BufferOverflowException in SocketChannelOutputBuffer #23

Closed
glassfishrobot opened this issue Sep 18, 2007 · 13 comments
Closed

BufferOverflowException in SocketChannelOutputBuffer #23

glassfishrobot opened this issue Sep 18, 2007 · 13 comments

Comments

@glassfishrobot
Copy link

public void realWriteBytes(byte cbuf[], int off, int len)
throws IOException {
if (len > 0) {
if (len > outputByteBuffer.remaining())

{ ByteBuffer tmp = ByteBuffer.allocate( outputByteBuffer.capacity() * 2 + len); outputByteBuffer.flip(); tmp.put(outputByteBuffer); outputByteBuffer = tmp; }

outputByteBuffer.put(cbuf, off, len);
}
}

if position + len is bigger than capacity * 2, outputByteBuffer overflows.

Environment

Operating System: All
Platform: All

Affected Versions

[1.9.22]

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Reported by iasandcb@java.net

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Was assigned to grizzly-issues

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
iasandcb@java.net said:
Created an attachment (id=3)
patch for this issue

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
File: ias-2007-09-17.patch
Attached By: iasandcb@java.net

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
iasandcb@java.net said:
Oops, sorry. The original code is
public void realWriteBytes(byte cbuf[], int off, int len)
throws IOException {
if (len > 0) {
if (len > outputByteBuffer.remaining())

{ ByteBuffer tmp = ByteBuffer.allocate( outputByteBuffer.capacity() * 2); outputByteBuffer.flip(); tmp.put(outputByteBuffer); outputByteBuffer = tmp; }

outputByteBuffer.put(cbuf, off, len);
}
}

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
jfarcand@java.net said:
Thanks! It was fixed in 1.0, but I forgot to port the fix.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
jfarcand@java.net said:
What about the fix from 1.0:

public void realWriteBytes(byte cbuf[], int off, int len)
throws IOException {
if (len > 0) {
if (len > outputByteBuffer.remaining())

{ int size = Math.max(outputByteBuffer.capacity() * 2, len + outputByteBuffer.position()); ByteBuffer tmp = ByteBuffer.allocate(size); outputByteBuffer.flip(); tmp.put(outputByteBuffer); outputByteBuffer = tmp; }

outputByteBuffer.put(cbuf, off, len);
}
}

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
iasandcb@java.net said:
+1

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
jfarcand@java.net said:
Fixed. Thanks!!

[ja120114@localhost trunk]$ svn commit
Sending
trunk/modules/http/src/main/java/com/sun/grizzly/http/SocketChannelOutputBuffer.java
Transmitting file data .
Committed revision 510.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
jfarcand@java.net said:
Fix milestones

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Marked as fixed on Wednesday, December 16th 2009, 6:14:16 pm

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
This issue was imported from java.net JIRA GRIZZLY-23

@glassfishrobot
Copy link
Author

@glassfishrobot glassfishrobot self-assigned this Feb 9, 2018
dmatej pushed a commit to dmatej/grizzly that referenced this issue Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant