소스 검색

Merge pull request #4739 from asimshankar/tf-bytesize

Graceful failure in SerializeToArray().
Feng Xiao 7 년 전
부모
커밋
36c5780a3d
1개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 1
      src/google/protobuf/message_lite.cc

+ 5 - 1
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);