diff options
author | Bo Yang <teboring@google.com> | 2016-09-19 13:45:07 -0700 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2016-10-10 11:23:36 -0700 |
commit | cc8ca5b6a5478b40546d4206392eb1471454460d (patch) | |
tree | c0b45abfa16d7d373a6ea8f7fe50f1de00ab938e /src/google/protobuf/message_lite.cc | |
parent | 337a028bb65ccca4dda768695950b5aba53ae2c9 (diff) |
Integrate internal changes
Diffstat (limited to 'src/google/protobuf/message_lite.cc')
-rw-r--r-- | src/google/protobuf/message_lite.cc | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index ba56db95..9d6da264 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -33,8 +33,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include <google/protobuf/message_lite.h> #include <google/protobuf/arena.h> +#include <google/protobuf/generated_message_util.h> +#include <google/protobuf/message_lite.h> #include <google/protobuf/repeated_field.h> #include <string> #include <google/protobuf/stubs/logging.h> @@ -58,9 +59,9 @@ namespace { // protobuf implementation but is more likely caused by concurrent modification // of the message. This function attempts to distinguish between the two and // provide a useful error message. -void ByteSizeConsistencyError(int byte_size_before_serialization, - int byte_size_after_serialization, - int bytes_produced_by_serialization, +void ByteSizeConsistencyError(size_t byte_size_before_serialization, + size_t byte_size_after_serialization, + size_t bytes_produced_by_serialization, const MessageLite& message) { GOOGLE_CHECK_EQ(byte_size_before_serialization, byte_size_after_serialization) << message.GetTypeName() @@ -236,12 +237,15 @@ bool MessageLite::SerializeToCodedStream(io::CodedOutputStream* output) const { return SerializePartialToCodedStream(output); } +size_t MessageLite::ByteSizeLong() const { + return internal::FromIntSize(ByteSize()); +} + bool MessageLite::SerializePartialToCodedStream( io::CodedOutputStream* output) const { - const int size = ByteSize(); // Force size to be cached. - if (size < 0) { - // Messages >2G cannot be serialized due to overflow computing ByteSize. - GOOGLE_LOG(ERROR) << "Error computing ByteSize (possible overflow?)."; + const size_t size = ByteSizeLong(); // Force size to be cached. + if (size > INT_MAX) { + GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB."; return false; } @@ -249,7 +253,7 @@ bool MessageLite::SerializePartialToCodedStream( if (buffer != NULL) { uint8* end = SerializeWithCachedSizesToArray(buffer); if (end - buffer != size) { - ByteSizeConsistencyError(size, ByteSize(), end - buffer, *this); + ByteSizeConsistencyError(size, ByteSizeLong(), end - buffer, *this); } return true; } else { @@ -261,7 +265,7 @@ bool MessageLite::SerializePartialToCodedStream( int final_byte_count = output->ByteCount(); if (final_byte_count - original_byte_count != size) { - ByteSizeConsistencyError(size, ByteSize(), + ByteSizeConsistencyError(size, ByteSizeLong(), final_byte_count - original_byte_count, *this); } @@ -287,11 +291,10 @@ bool MessageLite::AppendToString(string* output) const { } bool MessageLite::AppendPartialToString(string* output) const { - int old_size = output->size(); - int byte_size = ByteSize(); - if (byte_size < 0) { - // Messages >2G cannot be serialized due to overflow computing ByteSize. - GOOGLE_LOG(ERROR) << "Error computing ByteSize (possible overflow?)."; + size_t old_size = output->size(); + size_t byte_size = ByteSizeLong(); + if (byte_size > INT_MAX) { + GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB."; return false; } @@ -300,7 +303,7 @@ bool MessageLite::AppendPartialToString(string* output) const { reinterpret_cast<uint8*>(io::mutable_string_data(output) + old_size); uint8* end = SerializeWithCachedSizesToArray(start); if (end - start != byte_size) { - ByteSizeConsistencyError(byte_size, ByteSize(), end - start, *this); + ByteSizeConsistencyError(byte_size, ByteSizeLong(), end - start, *this); } return true; } @@ -321,12 +324,12 @@ bool MessageLite::SerializeToArray(void* data, int size) const { } bool MessageLite::SerializePartialToArray(void* data, int size) const { - int byte_size = ByteSize(); + int byte_size = ByteSizeLong(); if (size < byte_size) return false; uint8* start = reinterpret_cast<uint8*>(data); uint8* end = SerializeWithCachedSizesToArray(start); if (end - start != byte_size) { - ByteSizeConsistencyError(byte_size, ByteSize(), end - start, *this); + ByteSizeConsistencyError(byte_size, ByteSizeLong(), end - start, *this); } return true; } |