From 4e3258973f2546125ff9cdbc86664fe2fff38f13 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sat, 3 Nov 2012 20:00:48 +0100 Subject: [PATCH] [#707] Fix IndexOutOfBoundsException which could accour when the buffer is consolitated in the middle of an operation --- .../main/java/io/netty/buffer/DefaultCompositeByteBuf.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java b/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java index 7587ec3ea5..646bf33d0d 100644 --- a/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java @@ -181,7 +181,7 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit // Consolidate if the number of components will exceed the maximum by this operation. final int numComponents = components.size(); - if (numComponents + cnt > maxNumComponents) { + if (numComponents + cnt >= maxNumComponents) { final ByteBuf consolidated; if (numComponents != 0) { final int capacity = components.get(numComponents - 1).endOffset + readableBytes; @@ -230,6 +230,11 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit if (b.readable()) { addComponent(cIndex ++, b); + int size = components.size(); + if (cIndex > size) { + // was consolidated, so adjust index. #707 + cIndex = size; + } } } return this;