Fail if DynamicChannelBuffer attempts to exceed the max capacity (#258)

- Contributed by @normanmaurer
This commit is contained in:
Trustin Lee 2012-05-30 15:51:24 -07:00
parent 8eda2280b3
commit b5d715343a

View File

@ -73,6 +73,13 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
int minNewCapacity = writerIndex() + minWritableBytes; int minNewCapacity = writerIndex() + minWritableBytes;
while (newCapacity < minNewCapacity) { while (newCapacity < minNewCapacity) {
newCapacity <<= 1; 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("buffer capacity over 2GiB");
}
} }
ChannelBuffer newBuffer = factory().getBuffer(order(), newCapacity); ChannelBuffer newBuffer = factory().getBuffer(order(), newCapacity);