Fix IndexOutOfBoundsException for CompositeByteBuf #4679
Motivation: Modifications: Use the correct start index Result: Fixes #4679
This commit is contained in:
parent
301c40adbd
commit
6f8618889a
@ -525,7 +525,7 @@ public final class ByteBufUtil {
|
|||||||
try {
|
try {
|
||||||
buffer.writeBytes(src, readerIndex, len);
|
buffer.writeBytes(src, readerIndex, len);
|
||||||
// Use internalNioBuffer(...) to reduce object creation.
|
// Use internalNioBuffer(...) to reduce object creation.
|
||||||
decodeString(decoder, buffer.internalNioBuffer(readerIndex, len), dst);
|
decodeString(decoder, buffer.internalNioBuffer(0, len), dst);
|
||||||
} finally {
|
} finally {
|
||||||
// Release the temporary buffer again.
|
// Release the temporary buffer again.
|
||||||
buffer.release();
|
buffer.release();
|
||||||
|
@ -106,4 +106,17 @@ public class ByteBufUtilTest {
|
|||||||
Assert.assertEquals(text, ByteBufUtil.decodeString(buffer, 0, buffer.readableBytes(), charset));
|
Assert.assertEquals(text, ByteBufUtil.decodeString(buffer, 0, buffer.readableBytes(), charset));
|
||||||
buffer.release();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user