Merge pull request #4739 from asimshankar/tf-bytesize

Graceful failure in SerializeToArray().
This commit is contained in:
Feng Xiao 2018-06-18 13:53:19 -07:00 committed by GitHub
commit 36c5780a3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);