@@ -4356,7 +4356,6 @@ internal::DescriptorBuilder::DescriptorBuilder(
43564356 tables_(tables),
43574357 deferred_validation_(deferred_validation),
43584358 error_collector_(error_collector),
4359- had_errors_(false ),
43604359 possible_undeclared_dependency_(nullptr ),
43614360 undefine_resolved_name_(" " ) {}
43624361
@@ -4366,9 +4365,12 @@ PROTOBUF_NOINLINE void internal::DescriptorBuilder::AddError(
43664365 const absl::string_view element_name, const Message& descriptor,
43674366 DescriptorPool::ErrorCollector::ErrorLocation location,
43684367 absl::FunctionRef<std::string()> make_error) {
4368+ if (++error_count_ > kMaxNumErrors ) {
4369+ return ;
4370+ }
43694371 std::string error = make_error ();
43704372 if (error_collector_ == nullptr ) {
4371- if (!had_errors_ ) {
4373+ if (!has_errors () ) {
43724374 ABSL_LOG (ERROR ) << " Invalid proto descriptor for file \" " << filename_
43734375 << " \" :" ;
43744376 }
@@ -4377,7 +4379,6 @@ PROTOBUF_NOINLINE void internal::DescriptorBuilder::AddError(
43774379 error_collector_->RecordError (filename_, element_name, &descriptor,
43784380 location, error);
43794381 }
4380- had_errors_ = true ;
43814382}
43824383
43834384PROTOBUF_NOINLINE void internal::DescriptorBuilder::AddError (
@@ -4426,6 +4427,9 @@ PROTOBUF_NOINLINE void internal::DescriptorBuilder::AddWarning(
44264427 const absl::string_view element_name, const Message& descriptor,
44274428 DescriptorPool::ErrorCollector::ErrorLocation location,
44284429 absl::FunctionRef<std::string()> make_error) {
4430+ if (++warning_count_ > kMaxNumErrors ) {
4431+ return ;
4432+ }
44294433 std::string error = make_error ();
44304434 if (error_collector_ == nullptr ) {
44314435 ABSL_LOG (WARNING ) << filename_ << " " << element_name << " : " << error;
@@ -4845,7 +4849,7 @@ bool internal::DescriptorBuilder::AddSymbol(const absl::string_view full_name,
48454849 if (!file_tables_->AddAliasUnderParent (parent, name, symbol)) {
48464850 // This is only possible if there was already an error adding something of
48474851 // the same name.
4848- if (!had_errors_ ) {
4852+ if (!has_errors () ) {
48494853 ABSL_DLOG (FATAL ) << " \" " << full_name
48504854 << " \" not previously defined in "
48514855 " symbols_by_name_, but was defined in "
@@ -5785,7 +5789,7 @@ FileDescriptor* internal::DescriptorBuilder::BuildFileImpl(
57855789 // Interpret only the non-extension options first, including features and
57865790 // their extensions. This has to be done in two passes, since option
57875791 // extensions defined in this file may have features attached to them.
5788- if (!had_errors_ ) {
5792+ if (!has_errors () ) {
57895793 OptionInterpreter option_interpreter (this );
57905794 for (std::vector<OptionsToInterpret>::iterator iter =
57915795 options_to_interpret_.begin ();
@@ -5837,7 +5841,7 @@ FileDescriptor* internal::DescriptorBuilder::BuildFileImpl(
58375841
58385842 // Validate options. See comments at InternalSetLazilyBuildDependencies about
58395843 // error checking and lazy import building.
5840- if (!had_errors_ && !pool_->lazily_build_dependencies_ ) {
5844+ if (!has_errors () && !pool_->lazily_build_dependencies_ ) {
58415845 internal::VisitDescriptors (
58425846 *result, proto, [&](const auto & descriptor, const auto & desc_proto) {
58435847 ValidateOptions (&descriptor, desc_proto);
@@ -5846,7 +5850,7 @@ FileDescriptor* internal::DescriptorBuilder::BuildFileImpl(
58465850
58475851 // Additional naming conflict check for map entry types. Only need to check
58485852 // this if there are already errors.
5849- if (had_errors_ ) {
5853+ if (has_errors () ) {
58505854 for (int i = 0 ; i < proto.message_type_size (); ++i) {
58515855 DetectMapConflicts (result->message_type (i), proto.message_type (i));
58525856 }
@@ -5856,14 +5860,14 @@ FileDescriptor* internal::DescriptorBuilder::BuildFileImpl(
58565860 // Again, see comments at InternalSetLazilyBuildDependencies about error
58575861 // checking. Also, don't log unused dependencies if there were previous
58585862 // errors, since the results might be inaccurate.
5859- if (!had_errors_ && !unused_dependency_.empty () &&
5863+ if (!has_errors () && !unused_dependency_.empty () &&
58605864 !pool_->lazily_build_dependencies_ ) {
58615865 LogUnusedDependency (proto, result);
58625866 }
58635867
58645868 // Store feature information for deferred validation outside of the database
58655869 // mutex.
5866- if (!had_errors_ && !pool_->lazily_build_dependencies_ ) {
5870+ if (!has_errors () && !pool_->lazily_build_dependencies_ ) {
58675871 internal::VisitDescriptors (
58685872 *result, proto, [&](const auto & descriptor, const auto & desc_proto) {
58695873 if (!IsDefaultInstance (*descriptor.proto_features_ )) {
@@ -5880,7 +5884,7 @@ FileDescriptor* internal::DescriptorBuilder::BuildFileImpl(
58805884 });
58815885 }
58825886
5883- if (!had_errors_ && pool_->enforce_naming_style_ ) {
5887+ if (!has_errors () && pool_->enforce_naming_style_ ) {
58845888 internal::VisitDescriptors (
58855889 *result, proto, [&](const auto & descriptor, const auto & desc_proto) {
58865890 if (IsStyleOrGreater (&descriptor, FeatureSet::STYLE2024 )) {
@@ -5889,7 +5893,7 @@ FileDescriptor* internal::DescriptorBuilder::BuildFileImpl(
58895893 });
58905894 }
58915895
5892- if (!had_errors_ && pool_->enforce_proto_limits_ ) {
5896+ if (!has_errors () && pool_->enforce_proto_limits_ ) {
58935897 internal::VisitDescriptors (
58945898 *result, proto, [&](const auto & descriptor, const auto & desc_proto) {
58955899 if (internal::InternalFeatureHelper::GetFeatures (descriptor)
@@ -5899,7 +5903,7 @@ FileDescriptor* internal::DescriptorBuilder::BuildFileImpl(
58995903 }
59005904 });
59015905 }
5902- if (!had_errors_ && pool_->enforce_symbol_visibility_ ) {
5906+ if (!has_errors () && pool_->enforce_symbol_visibility_ ) {
59035907 SymbolChecker symbol_checker (result, proto);
59045908 // Check Symbol Visibility and future co-location Rules.
59055909 auto errors = symbol_checker.CheckSymbolVisibilityRules ();
@@ -5912,7 +5916,7 @@ FileDescriptor* internal::DescriptorBuilder::BuildFileImpl(
59125916 }
59135917 }
59145918
5915- if (had_errors_ ) {
5919+ if (has_errors () ) {
59165920 return nullptr ;
59175921 } else {
59185922 return result;
@@ -7057,7 +7061,7 @@ void internal::DescriptorBuilder::CrossLinkMessage(
70577061 out_oneof_decl.fields_ = message->field (i);
70587062 }
70597063
7060- if (!had_errors_ ) {
7064+ if (!has_errors () ) {
70617065 // Verify that they are contiguous.
70627066 // This is assumed by OneofDescriptor::field(i).
70637067 // But only if there are no errors.
@@ -7118,13 +7122,13 @@ void internal::DescriptorBuilder::CrossLinkMessage(
71187122void internal::DescriptorBuilder::CheckExtensionDeclarationFieldType (
71197123 const FieldDescriptor& field, const FieldDescriptorProto& proto,
71207124 absl::string_view type) {
7121- if (had_errors_ ) return ;
7125+ if (has_errors () ) return ;
71227126 std::string actual_type (field.type_name ());
71237127 std::string expected_type (type);
71247128 if (field.message_type () || field.enum_type ()) {
71257129 // Field message type descriptor can be in a partial state which will cause
71267130 // segmentation fault if it is being accessed.
7127- if (had_errors_ ) return ;
7131+ if (has_errors () ) return ;
71287132 absl::string_view full_name = field.message_type () != nullptr
71297133 ? field.message_type ()->full_name ()
71307134 : field.enum_type ()->full_name ();
0 commit comments