From 307aeac9cf1b31a217921198e46a847179723240 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 29 Jan 2024 15:23:18 -0800 Subject: [PATCH] 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 --- src/google/protobuf/descriptor.cc | 3 ++- src/google/protobuf/descriptor_unittest.cc | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 08870ccac0..901f883874 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -7737,7 +7737,8 @@ void DescriptorBuilder::ValidateOptions(const FieldDescriptor* field, // The following check is temporarily OSS only till we fix all affected // google3 TAP tests. - if (field->options().has_ctype()) { + if (field->file()->edition() >= Edition::EDITION_2023 && + field->options().has_ctype()) { if (field->cpp_type() != FieldDescriptor::CPPTYPE_STRING) { AddError( field->full_name(), proto, DescriptorPool::ErrorCollector::TYPE, diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index f0b6eef050..de25e35476 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -2957,6 +2957,9 @@ TEST_F(MiscTest, InvalidFieldOptions) { FileDescriptorProto file_proto; file_proto.set_name("foo.proto"); + file_proto.set_syntax("editions"); + file_proto.set_edition(Edition::EDITION_2023); + DescriptorProto* message_proto = AddMessage(&file_proto, "TestMessage"); AddField(message_proto, "foo", 1, FieldDescriptorProto::LABEL_OPTIONAL, FieldDescriptorProto::TYPE_INT32);