Commit 0068b251 authored by Mitchel's avatar Mitchel Committed by Wouter van Oortmerssen

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

parent ec74f58b
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment