Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

BufferOverflowException in SocketChannelOutputBuffer #23

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

BufferOverflowException in SocketChannelOutputBuffer #23

glassfishrobot opened this issue Sep 18, 2007 · 12 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

Reported by iasandcb@java.net

@glassfishrobot
Copy link
Author

Was assigned to grizzly-issues

@glassfishrobot
Copy link
Author

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

@glassfishrobot
Copy link
Author

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

@glassfishrobot
Copy link
Author

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

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

@glassfishrobot
Copy link
Author

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

iasandcb@java.net said:
+1

@glassfishrobot
Copy link
Author

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

jfarcand@java.net said:
Fix milestones

@glassfishrobot
Copy link
Author

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

@glassfishrobot
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant