@@ -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) {
@@ -1958,23 +1965,19 @@ TextFormat::Parser::Parser()
19581965 allow_singular_overwrites_(false ),
19591966 recursion_limit_(kDefaultRecursionLimit ) {}
19601967
1961- namespace {
1962-
19631968template <typename T>
1964- bool CheckParseInputSize (T& input, io::ErrorCollector* error_collector) {
1969+ bool TextFormat::Parser:: CheckParseInputSize (T& input, Message* output) const {
19651970 if (input.size () > INT_MAX ) {
1966- error_collector-> RecordError (
1967- - 1 , 0 ,
1968- absl::StrCat (
1969- " Input size too large: " , static_cast < int64_t >(input. size () ),
1970- " bytes " , " > " , INT_MAX , " bytes. " ) );
1971+ ReportErrorImpl (- 1 , 0 ,
1972+ absl::StrCat ( " Input size too large: " ,
1973+ static_cast < int64_t >(input. size ()), " bytes " ,
1974+ " > " , INT_MAX , " bytes. " ),
1975+ output-> GetDescriptor (), error_collector_ );
19711976 return false ;
19721977 }
19731978 return true ;
19741979}
19751980
1976- } // namespace
1977-
19781981bool TextFormat::Parser::Parse (io::ZeroCopyInputStream* input,
19791982 Message* output) {
19801983 output->Clear ();
@@ -1994,14 +1997,14 @@ bool TextFormat::Parser::Parse(io::ZeroCopyInputStream* input,
19941997
19951998bool TextFormat::Parser::ParseFromString (absl::string_view input,
19961999 Message* output) {
1997- DO (CheckParseInputSize (input, error_collector_ ));
2000+ DO (CheckParseInputSize (input, output ));
19982001 io::ArrayInputStream input_stream (input.data (), input.size ());
19992002 return Parse (&input_stream, output);
20002003}
20012004
20022005bool TextFormat::Parser::ParseFromCord (const absl::Cord& input,
20032006 Message* output) {
2004- DO (CheckParseInputSize (input, error_collector_ ));
2007+ DO (CheckParseInputSize (input, output ));
20052008 io::CordInputStream input_stream (&input);
20062009 return Parse (&input_stream, output);
20072010}
@@ -2019,7 +2022,7 @@ bool TextFormat::Parser::Merge(io::ZeroCopyInputStream* input,
20192022
20202023bool TextFormat::Parser::MergeFromString (absl::string_view input,
20212024 Message* output) {
2022- DO (CheckParseInputSize (input, error_collector_ ));
2025+ DO (CheckParseInputSize (input, output ));
20232026 io::ArrayInputStream input_stream (input.data (), input.size ());
20242027 return Merge (&input_stream, output);
20252028}
0 commit comments