Skip to content

Commit 5dc171f

Browse files
Extension declaration: Enforce that if the extension range has a declaration then all extensions in that range must be declared. This should prevent non-declared extensions from being added.
PiperOrigin-RevId: 520415909
1 parent db126ca commit 5dc171f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/google/protobuf/descriptor.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7220,6 +7220,17 @@ void DescriptorBuilder::ValidateFieldOptions(
72207220
return;
72217221
}
72227222

7223+
if (!extension_range->options_->declaration().empty()) {
7224+
AddError(field->full_name(), proto,
7225+
DescriptorPool::ErrorCollector::EXTENDEE,
7226+
absl::Substitute(
7227+
"Missing extension declaration for field $0 with number $1. "
7228+
"An extension range must declare for all extension fields "
7229+
"once if there's any declaration in the range. Otherwise, "
7230+
"consider splitting up the range.",
7231+
field->full_name(), field->number()));
7232+
return;
7233+
}
72237234
}
72247235
}
72257236

0 commit comments

Comments
 (0)