Fix for Java infinite loop encoding into 0-sized buffer (#4654)

This commit is contained in:
Mitchel
2018-03-02 18:21:08 -05:00
committed by Wouter van Oortmerssen
parent ec74f58b94
commit 0068b25132

View File

@@ -196,7 +196,7 @@ public class FlatBufferBuilder {
int old_buf_size = bb.capacity();
if ((old_buf_size & 0xC0000000) != 0) // Ensure we don't grow beyond what fits in an int.
throw new AssertionError("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");
int new_buf_size = old_buf_size << 1;
int new_buf_size = old_buf_size == 0 ? 1 : old_buf_size << 1;
bb.position(0);
ByteBuffer nbb = bb_factory.newByteBuffer(new_buf_size);
nbb.position(new_buf_size - old_buf_size);