Skip to content

Commit

Permalink
Fix IndexOutOfBoundsException for CompositeByteBuf #4679
Browse files Browse the repository at this point in the history
Motivation:

Modifications:

Use the correct start index

Result:

Fixes #4679
  • Loading branch information
windie authored and Scottmitch committed Jan 9, 2016
1 parent 301c40a commit 6f86188
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion buffer/src/main/java/io/netty/buffer/ByteBufUtil.java
Expand Up @@ -525,7 +525,7 @@ static String decodeString(ByteBuf src, int readerIndex, int len, Charset charse
try {
buffer.writeBytes(src, readerIndex, len);
// Use internalNioBuffer(...) to reduce object creation.
decodeString(decoder, buffer.internalNioBuffer(readerIndex, len), dst);
decodeString(decoder, buffer.internalNioBuffer(0, len), dst);
} finally {
// Release the temporary buffer again.
buffer.release();
Expand Down
13 changes: 13 additions & 0 deletions buffer/src/test/java/io/netty/buffer/ByteBufUtilTest.java
Expand Up @@ -106,4 +106,17 @@ private static void testDecodeString(String text, Charset charset) {
Assert.assertEquals(text, ByteBufUtil.decodeString(buffer, 0, buffer.readableBytes(), charset));
buffer.release();
}

@Test
public void testToStringDoesNotThrowIndexOutOfBounds() {
CompositeByteBuf buffer = Unpooled.compositeBuffer();
try {
byte[] bytes = "1234".getBytes(CharsetUtil.UTF_8);
buffer.addComponent(Unpooled.buffer(bytes.length).writeBytes(bytes));
buffer.addComponent(Unpooled.buffer(bytes.length).writeBytes(bytes));
Assert.assertEquals("1234", buffer.toString(bytes.length, bytes.length, CharsetUtil.UTF_8));
} finally {
buffer.release();
}
}
}

0 comments on commit 6f86188

Please sign in to comment.