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
pull/15639/head
Protobuf Team Bot 10 months ago committed by Copybara-Service
parent fd82df7dba
commit 307aeac9cf
  1. 3
      src/google/protobuf/descriptor.cc
  2. 3
      src/google/protobuf/descriptor_unittest.cc

@ -7737,7 +7737,8 @@ void DescriptorBuilder::ValidateOptions(const FieldDescriptor* field,
// The following check is temporarily OSS only till we fix all affected // The following check is temporarily OSS only till we fix all affected
// google3 TAP tests. // 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) { if (field->cpp_type() != FieldDescriptor::CPPTYPE_STRING) {
AddError( AddError(
field->full_name(), proto, DescriptorPool::ErrorCollector::TYPE, field->full_name(), proto, DescriptorPool::ErrorCollector::TYPE,

@ -2957,6 +2957,9 @@ TEST_F(MiscTest, InvalidFieldOptions) {
FileDescriptorProto file_proto; FileDescriptorProto file_proto;
file_proto.set_name("foo.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"); DescriptorProto* message_proto = AddMessage(&file_proto, "TestMessage");
AddField(message_proto, "foo", 1, FieldDescriptorProto::LABEL_OPTIONAL, AddField(message_proto, "foo", 1, FieldDescriptorProto::LABEL_OPTIONAL,
FieldDescriptorProto::TYPE_INT32); FieldDescriptorProto::TYPE_INT32);

Loading…
Cancel
Save