aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Eisenbach <eisenbach@google.com>2015-05-04 14:00:47 -0700
committerAndre Eisenbach <eisenbach@google.com>2015-05-04 22:11:36 -0700
commit4d8b123b8985b3f87a640be2d9a1b4b730b5fdca (patch)
treef967bff0556f64e0ce9ea4fd8ce5b557f64ed1a8
parent90ca7bfb7fc5c91f1593ad0efb8e294cf956b5c4 (diff)
downloadexternal_protobuf-4d8b123b8985b3f87a640be2d9a1b4b730b5fdca.zip
external_protobuf-4d8b123b8985b3f87a640be2d9a1b4b730b5fdca.tar.gz
external_protobuf-4d8b123b8985b3f87a640be2d9a1b4b730b5fdca.tar.bz2
Handle 0-length byte buffers in micro and nano protobufs
Change-Id: I845ee1ab1005d25c8d77a8c2ed801c0f7b7c847b
-rw-r--r--java/src/main/java/com/google/protobuf/micro/CodedInputStreamMicro.java2
-rw-r--r--java/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java2
2 files changed, 4 insertions, 0 deletions
diff --git a/java/src/main/java/com/google/protobuf/micro/CodedInputStreamMicro.java b/java/src/main/java/com/google/protobuf/micro/CodedInputStreamMicro.java
index 3e3926c..cf1dc67 100644
--- a/java/src/main/java/com/google/protobuf/micro/CodedInputStreamMicro.java
+++ b/java/src/main/java/com/google/protobuf/micro/CodedInputStreamMicro.java
@@ -243,6 +243,8 @@ public final class CodedInputStreamMicro {
final ByteStringMicro result = ByteStringMicro.copyFrom(buffer, bufferPos, size);
bufferPos += size;
return result;
+ } else if (size == 0) {
+ return ByteStringMicro.EMPTY;
} else {
// Slow path: Build a byte array first then copy it.
return ByteStringMicro.copyFrom(readRawBytes(size));
diff --git a/java/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java b/java/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java
index c5fea5a..df7fee0 100644
--- a/java/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java
+++ b/java/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java
@@ -236,6 +236,8 @@ public final class CodedInputByteBufferNano {
System.arraycopy(buffer, bufferPos, result, 0, size);
bufferPos += size;
return result;
+ } else if (size == 0) {
+ return WireFormatNano.EMPTY_BYTES;
} else {
// Slow path: Build a byte array first then copy it.
return readRawBytes(size);