CodeOutputStream was writing to a flat byte array and ran out of space

For a message like this

messages Orders {
  repeated Order payloads = 1;
}
message Order {
  ...
}

Actually this can be any message with size above ~2GB.
With a toByte call, it would result in CodeOutputStream was writing to a flat byte array and ran out of space.

sample code:

  Any.pack(orders).toByteArray();

This is actually an issue with the size variable being an int. Hence, the message.getSerializedSize() would give a wrong value (smaller than its real size). Hence, when the CodeOutputStream was trying to write the bytes, eventually it write more than the limit which is from message.getSerializedSize().

https://github.com/protocolbuffers/protobuf/issues/10033

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s