From 4d8b123b8985b3f87a640be2d9a1b4b730b5fdca Mon Sep 17 00:00:00 2001 From: Andre Eisenbach Date: Mon, 4 May 2015 14:00:47 -0700 Subject: Handle 0-length byte buffers in micro and nano protobufs Change-Id: I845ee1ab1005d25c8d77a8c2ed801c0f7b7c847b --- java/src/main/java/com/google/protobuf/micro/CodedInputStreamMicro.java | 2 ++ .../main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java | 2 ++ 2 files changed, 4 insertions(+) (limited to 'java') 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); -- cgit v1.1