Skip to content

Commit 0090f19

Browse files
Check ctype() in DescriptorBuilder for edition 2023 and beyond.
It seems possible that old data is stored with serialized descriptors. If we reject old descriptors due to invalid ctype, the change effectively becomes breaking changes. We should apply this stricter check for edition 2023 or beyond. PiperOrigin-RevId: 602516135
1 parent 624d65d commit 0090f19

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/google/protobuf/descriptor.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7723,7 +7723,8 @@ void DescriptorBuilder::ValidateOptions(const FieldDescriptor* field,
77237723

77247724
// The following check is temporarily OSS only till we fix all affected
77257725
// google3 TAP tests.
7726-
if (field->options().has_ctype()) {
7726+
if (field->file()->edition() >= Edition::EDITION_2023 &&
7727+
field->options().has_ctype()) {
77277728
if (field->cpp_type() != FieldDescriptor::CPPTYPE_STRING) {
77287729
AddError(
77297730
field->full_name(), proto, DescriptorPool::ErrorCollector::TYPE,

src/google/protobuf/descriptor_unittest.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,9 @@ TEST_F(MiscTest, InvalidFieldOptions) {
29472947
FileDescriptorProto file_proto;
29482948
file_proto.set_name("foo.proto");
29492949

2950+
file_proto.set_syntax("editions");
2951+
file_proto.set_edition(Edition::EDITION_2023);
2952+
29502953
DescriptorProto* message_proto = AddMessage(&file_proto, "TestMessage");
29512954
AddField(message_proto, "foo", 1, FieldDescriptorProto::LABEL_OPTIONAL,
29522955
FieldDescriptorProto::TYPE_INT32);

0 commit comments

Comments
 (0)