Thank Em Rauch for your response.
Your suspicion on attack surface actually piqued my interest and I wanted to check if its possible
```
Without other context and doing more archeology, I actually suspect the 'attack' was more that e.g. sufficiently smart attackers could send a string which is length "2GB minus one byte", and then know that the service boxes up that input in a protobuf message (adding a few bytes over overhead), and then encode that to the next backend server.
```
Given data is read via the codedinputstream a small unit test would have been able to uncover the possibility of the same
1. For test purposes reduced the current limit size to say 12 and buffer size to 4
2. Interestingly there are already present defensive measures to check that size limits are respected, eg in 2.5 version we have this check
// if (totalBytesRetired + bufferPos + size > currentLimit) {raise exception
public void testCurrentLimitExceededOld() throws Exception {
byte[] bytes = "123456789999".getBytes("UTF-8");
ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
CodedOutputStream output = CodedOutputStream.newInstance(rawOutput, bytes.length);
int tag = WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED);
output.writeRawVarint32(bytes.length);
output.writeRawBytes(bytes);
output.flush();
byte[] rawInput = rawOutput.toByteArray();
CodedInputStream input = CodedInputStream.newInstance(
new ByteArrayInputStream(rawInput));
// The length of the whole rawInput
input.setSizeLimit(14);
System.out.println(input.readString());
}
By the way, there are definite JNI calls for memory copy starting from 3.0 version , however all these calls are well protected via length and index checks.
So it does appear the version is immune to the vulnerability in question
Regards,
Somak