aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeng Xiao <xfxyjwf@gmail.com>2018-06-18 13:53:19 -0700
committerGitHub <noreply@github.com>2018-06-18 13:53:19 -0700
commit36c5780a3d7f620d0d919f9e80b67780a443f4f7 (patch)
tree92afcdea1351a2ca371ff43a732612d3e3b375a9
parentb40cb4bc8bd233330cba2ab09d6e3016b004dce0 (diff)
parent2020e3d5eed3029287afb6002266131d87f881e8 (diff)
downloadprotobuf-36c5780a3d7f620d0d919f9e80b67780a443f4f7.tar.gz
protobuf-36c5780a3d7f620d0d919f9e80b67780a443f4f7.tar.bz2
protobuf-36c5780a3d7f620d0d919f9e80b67780a443f4f7.zip
Merge pull request #4739 from asimshankar/tf-bytesize
Graceful failure in SerializeToArray().
-rw-r--r--src/google/protobuf/message_lite.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc
index 123b142d..65af7cea 100644
--- a/src/google/protobuf/message_lite.cc
+++ b/src/google/protobuf/message_lite.cc
@@ -316,7 +316,11 @@ bool MessageLite::SerializeToArray(void* data, int size) const {
}
bool MessageLite::SerializePartialToArray(void* data, int size) const {
- int byte_size = ByteSizeLong();
+ size_t byte_size = ByteSizeLong();
+ if (byte_size > INT_MAX) {
+ GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB: " << size;
+ return false;
+ }
if (size < byte_size) return false;
uint8* start = reinterpret_cast<uint8*>(data);
uint8* end = SerializeWithCachedSizesToArray(start);