Don't throw if null is given as ByteBuf when adding components. (#11613)
Motivation:
232c669fa4
did add some overflow protection but did not handle null elements in the array the same as before.
Modifications:
- Break the loop if a null element was found
- Add unit test
Result:
Fixes https://github.com/netty/netty/issues/11612
This commit is contained in:
parent
60f8ed01cd
commit
6b7c58a2f9
@ -375,7 +375,11 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
|
||||
int readableBytes = 0;
|
||||
int capacity = capacity();
|
||||
for (int i = arrOffset; i < buffers.length; i++) {
|
||||
readableBytes += buffers[i].readableBytes();
|
||||
ByteBuf b = buffers[i];
|
||||
if (b == null) {
|
||||
break;
|
||||
}
|
||||
readableBytes += b.readableBytes();
|
||||
|
||||
// Check if we would overflow.
|
||||
// See https://github.com/netty/netty/issues/10194
|
||||
|
@ -1576,6 +1576,20 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
assertTrue(cbuf.release());
|
||||
}
|
||||
|
||||
// See https://github.com/netty/netty/issues/11612
|
||||
@Test
|
||||
public void testAddComponentWithNullEntry() {
|
||||
final ByteBuf buffer = Unpooled.buffer(8).writeZero(8);
|
||||
final CompositeByteBuf compositeByteBuf = compositeBuffer(Integer.MAX_VALUE);
|
||||
try {
|
||||
compositeByteBuf.addComponents(true, new ByteBuf[] { buffer, null });
|
||||
assertEquals(8, compositeByteBuf.readableBytes());
|
||||
assertEquals(1, compositeByteBuf.numComponents());
|
||||
} finally {
|
||||
compositeByteBuf.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverflowWhileAddingComponent() {
|
||||
int capacity = 1024 * 1024; // 1MB
|
||||
|
Loading…
Reference in New Issue
Block a user