diff --git a/buffer/src/main/java/io/netty/buffer/DynamicChannelBuffer.java b/buffer/src/main/java/io/netty/buffer/DynamicChannelBuffer.java index 2ea089c46b..83a202ad4f 100644 --- a/buffer/src/main/java/io/netty/buffer/DynamicChannelBuffer.java +++ b/buffer/src/main/java/io/netty/buffer/DynamicChannelBuffer.java @@ -73,6 +73,15 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer { int minNewCapacity = writerIndex() + minWritableBytes; while (newCapacity < minNewCapacity) { newCapacity <<= 1; + + + // Check if we exceeded the maximum size of 2gb if this is the case then + // newCapacity == 0 + // + // https://github.com/netty/netty/issues/258 + if (newCapacity == 0) { + throw new IllegalStateException("Maximum size of 2gb exceeded"); + } } ChannelBuffer newBuffer = factory().getBuffer(order(), newCapacity);