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
839dde1183
commit
e21591fa25
@ -374,7 +374,11 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
|
|||||||
int readableBytes = 0;
|
int readableBytes = 0;
|
||||||
int capacity = capacity();
|
int capacity = capacity();
|
||||||
for (int i = arrOffset; i < buffers.length; i++) {
|
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.
|
// Check if we would overflow.
|
||||||
// See https://github.com/netty/netty/issues/10194
|
// See https://github.com/netty/netty/issues/10194
|
||||||
|
@ -1555,6 +1555,20 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
|||||||
assertTrue(cbuf.release());
|
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
|
@Test
|
||||||
public void testOverflowWhileAddingComponent() {
|
public void testOverflowWhileAddingComponent() {
|
||||||
int capacity = 1024 * 1024; // 1MB
|
int capacity = 1024 * 1024; // 1MB
|
||||||
|
Loading…
Reference in New Issue
Block a user