diff options
author | Brian Duff <bduff@google.com> | 2015-06-18 17:59:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-06-18 17:59:05 +0000 |
commit | 1817ed30d663c9205feb3f0ae80e4c4f6eaa4c3d (patch) | |
tree | a688b1b0bad4efd9d365215085d1f454a4f6317a | |
parent | 89fa3126cb321cdb261178baf6267a369f69bfee (diff) | |
parent | d2195e15b89fe9face5eb71340acd288148f25e8 (diff) | |
download | external_protobuf-android-m-preview-1.zip external_protobuf-android-m-preview-1.tar.gz external_protobuf-android-m-preview-1.tar.bz2 |
Merge "Update CodedOutputByteBufferNano to properly handle a malformed surrogate pair with a buffer too small to output a potentially well formed surrogate pair. This behavior mimics that of the ByteBuffer based methods."android-m-preview-1
-rw-r--r-- | java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java b/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java index 304c042..662f0fa 100644 --- a/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java +++ b/java/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java @@ -500,6 +500,13 @@ public final class CodedOutputByteBufferNano { bytes[j++] = (byte) (0x80 | (0x3F & (codePoint >>> 6))); bytes[j++] = (byte) (0x80 | (0x3F & codePoint)); } else { + // If we are surrogates and we're not a surrogate pair, always throw an + // IllegalArgumentException instead of an ArrayOutOfBoundsException. + if ((Character.MIN_SURROGATE <= c && c <= Character.MAX_SURROGATE) + && (i + 1 == sequence.length() + || !Character.isSurrogatePair(c, sequence.charAt(i + 1)))) { + throw new IllegalArgumentException("Unpaired surrogate at index " + i); + } throw new ArrayIndexOutOfBoundsException("Failed writing " + c + " at index " + j); } } |