@@ -337,6 +337,24 @@ const Descriptor* DefaultFinderFindAnyType(const Message& message,
337337 const std::string& name) {
338338 return message.GetDescriptor ()->file ()->pool ()->FindMessageTypeByName (name);
339339}
340+
341+ void ReportErrorImpl (int line, int col, absl::string_view message,
342+ const Descriptor* root_message_type,
343+ io::ErrorCollector* error_collector) {
344+ if (error_collector == nullptr ) {
345+ if (line >= 0 ) {
346+ ABSL_LOG (ERROR ) << " Error parsing text-format "
347+ << root_message_type->full_name () << " : " << (line + 1 )
348+ << " :" << (col + 1 ) << " : " << message;
349+ } else {
350+ ABSL_LOG (ERROR ) << " Error parsing text-format "
351+ << root_message_type->full_name () << " : " << message;
352+ }
353+ } else {
354+ error_collector->RecordError (line, col, message);
355+ }
356+ }
357+
340358} // namespace
341359
342360auto TextFormat::Parser::UnsetFieldsMetadata::GetUnsetFieldId (
@@ -454,18 +472,7 @@ class TextFormat::Parser::ParserImpl {
454472
455473 void ReportError (int line, int col, absl::string_view message) {
456474 had_errors_ = true ;
457- if (error_collector_ == nullptr ) {
458- if (line >= 0 ) {
459- ABSL_LOG (ERROR ) << " Error parsing text-format "
460- << root_message_type_->full_name () << " : " << (line + 1 )
461- << " :" << (col + 1 ) << " : " << message;
462- } else {
463- ABSL_LOG (ERROR ) << " Error parsing text-format "
464- << root_message_type_->full_name () << " : " << message;
465- }
466- } else {
467- error_collector_->RecordError (line, col, message);
468- }
475+ ReportErrorImpl (line, col, message, root_message_type_, error_collector_);
469476 }
470477
471478 void ReportWarning (int line, int col, const absl::string_view message) {
@@ -1959,23 +1966,19 @@ TextFormat::Parser::Parser()
19591966 allow_singular_overwrites_(false ),
19601967 recursion_limit_(kDefaultRecursionLimit ) {}
19611968
1962- namespace {
1963-
19641969template <typename T>
1965- bool CheckParseInputSize (T& input, io::ErrorCollector* error_collector) {
1970+ bool TextFormat::Parser:: CheckParseInputSize (T& input, Message* output) const {
19661971 if (input.size () > INT_MAX ) {
1967- error_collector-> RecordError (
1968- - 1 , 0 ,
1969- absl::StrCat (
1970- " Input size too large: " , static_cast < int64_t >(input. size () ),
1971- " bytes " , " > " , INT_MAX , " bytes. " ) );
1972+ ReportErrorImpl (- 1 , 0 ,
1973+ absl::StrCat ( " Input size too large: " ,
1974+ static_cast < int64_t >(input. size ()), " bytes " ,
1975+ " > " , INT_MAX , " bytes. " ),
1976+ output-> GetDescriptor (), error_collector_ );
19721977 return false ;
19731978 }
19741979 return true ;
19751980}
19761981
1977- } // namespace
1978-
19791982bool TextFormat::Parser::Parse (io::ZeroCopyInputStream* input,
19801983 Message* output) {
19811984 output->Clear ();
@@ -1995,14 +1998,14 @@ bool TextFormat::Parser::Parse(io::ZeroCopyInputStream* input,
19951998
19961999bool TextFormat::Parser::ParseFromString (absl::string_view input,
19972000 Message* output) {
1998- DO (CheckParseInputSize (input, error_collector_ ));
2001+ DO (CheckParseInputSize (input, output ));
19992002 io::ArrayInputStream input_stream (input.data (), input.size ());
20002003 return Parse (&input_stream, output);
20012004}
20022005
20032006bool TextFormat::Parser::ParseFromCord (const absl::Cord& input,
20042007 Message* output) {
2005- DO (CheckParseInputSize (input, error_collector_ ));
2008+ DO (CheckParseInputSize (input, output ));
20062009 io::CordInputStream input_stream (&input);
20072010 return Parse (&input_stream, output);
20082011}
@@ -2020,7 +2023,7 @@ bool TextFormat::Parser::Merge(io::ZeroCopyInputStream* input,
20202023
20212024bool TextFormat::Parser::MergeFromString (absl::string_view input,
20222025 Message* output) {
2023- DO (CheckParseInputSize (input, error_collector_ ));
2026+ DO (CheckParseInputSize (input, output ));
20242027 io::ArrayInputStream input_stream (input.data (), input.size ());
20252028 return Merge (&input_stream, output);
20262029}
0 commit comments