[#1976] Fix IndexOutOfBoundsException when calling CompositeByteBuf.discardReadComponents()
This commit is contained in:
parent
e4f391f626
commit
b00f8c6390
@ -1257,9 +1257,10 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
|
|||||||
|
|
||||||
// Update indexes and markers.
|
// Update indexes and markers.
|
||||||
Component first = components.get(0);
|
Component first = components.get(0);
|
||||||
|
int offset = first.offset;
|
||||||
updateComponentOffsets(0);
|
updateComponentOffsets(0);
|
||||||
setIndex(readerIndex - first.offset, writerIndex - first.offset);
|
setIndex(readerIndex - offset, writerIndex - offset);
|
||||||
adjustMarkers(first.offset);
|
adjustMarkers(offset);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,4 +790,22 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
|||||||
buf.addComponent(buffer().writeByte(1));
|
buf.addComponent(buffer().writeByte(1));
|
||||||
assertFalse(buf.isDirect());
|
assertFalse(buf.isDirect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See https://github.com/netty/netty/issues/1976
|
||||||
|
@Test
|
||||||
|
public void testDiscardSomeReadBytes() {
|
||||||
|
CompositeByteBuf cbuf = freeLater(compositeBuffer());
|
||||||
|
int len = 8 * 4;
|
||||||
|
for (int i = 0; i < len; i += 4) {
|
||||||
|
ByteBuf buf = Unpooled.buffer().writeInt(i);
|
||||||
|
cbuf.capacity(cbuf.writerIndex()).addComponent(buf).writerIndex(i + 4);
|
||||||
|
}
|
||||||
|
cbuf.writeByte(1);
|
||||||
|
|
||||||
|
byte[] me = new byte[len];
|
||||||
|
cbuf.readBytes(me);
|
||||||
|
cbuf.readByte();
|
||||||
|
|
||||||
|
cbuf.discardSomeReadBytes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user