ARTEMIS-570 Fix buffer size overflow ProtonHandler

There is a race condition in the ProtonHandlerImpl.outputBuffer()
method.  The method checks to see how many bytes (n) are pending in the
underlying ProtonJ buffer, then creates a Netty buffer of size n.  It
then writes the contents of the pending ProtonJ head.  However, ProtonJ
can still write to it's internal buffer, meaning that it's buffer.size >
n causing an illegalArgumentException.  This patch fixes it by only
writing 'n' bytes to the Netty buffer.
This commit is contained in:
Martyn Taylor 2016-06-16 16:02:23 +01:00 committed by Clebert Suconic
parent 07b57e524a
commit 432e2ce178
1 changed files with 1 additions and 0 deletions

View File

@ -259,6 +259,7 @@ public class ProtonHandlerImpl extends ProtonInitializable implements ProtonHand
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(size); ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer(size);
ByteBuffer head = transport.head(); ByteBuffer head = transport.head();
head.position(offset); head.position(offset);
head.limit(offset + size);
buffer.writeBytes(head); buffer.writeBytes(head);
offset += size; // incrementing offset for future calls offset += size; // incrementing offset for future calls
return buffer; return buffer;