Give a clear error message on overflow in CodedOutputStream when a generator constructs a >2GB response file. PiperOrigin-RevId: 930009207
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index eae3e6f..7599793 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -3076,6 +3076,16 @@ return false; } + // This is only reachable for generators that are statically linked into + // protoc. For subprocess plugins, their responses go through wire-format + // parsing which already rejects payloads > 2 GiB. + if (output_file.content().size() > INT_MAX) { + *error = absl::Substitute( + "$0: Generated file $1 is too large (exceeds 2 GiB limit).", + plugin_name, output_file.name()); + return false; + } + // Use CodedOutputStream for convenience; otherwise we'd need to provide // our own buffer-copying loop. io::CodedOutputStream writer(current_output.get());