From 81106b10dc6b224a79ca2bc27768c1348e8776b6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 21 Apr 2023 14:01:49 -0700 Subject: [PATCH] Automated rollback of commit 57d5ede3ec807851ed9293f96aff8651b64f1e4d. PiperOrigin-RevId: 526130253 --- src/google/protobuf/descriptor.cc | 9 +++++++-- src/google/protobuf/descriptor_unittest.cc | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 27b4acbb97..8f7cf9a00b 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -5927,8 +5927,13 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, case FieldDescriptor::CPPTYPE_STRING: if (result->type() == FieldDescriptor::TYPE_BYTES) { std::string value; - absl::CUnescape(proto.default_value(), &value); - result->default_value_string_ = alloc.AllocateStrings(value); + if (absl::CUnescape(proto.default_value(), &value)) { + result->default_value_string_ = alloc.AllocateStrings(value); + } else { + AddError(result->full_name(), proto, + DescriptorPool::ErrorCollector::DEFAULT_VALUE, + "Invalid escaping in default value."); + } } else { result->default_value_string_ = alloc.AllocateStrings(proto.default_value()); diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index ba00a44ca4..23ba234a2a 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -4548,6 +4548,12 @@ TEST_F(ValidationErrorTest, InvalidDefaults) { " field { name: \"corge\" number: 6 label: LABEL_REPEATED type: " "TYPE_INT32" " default_value: \"1\" }" + + // Invalid CEscaped bytes default. + " field { name: \"bytes_default\" number: 7 label: LABEL_OPTIONAL " + " type: TYPE_BYTES" + " default_value: \"\\\\\" }" + "}", "foo.proto: Foo.foo: DEFAULT_VALUE: Couldn't parse default value " @@ -4558,6 +4564,8 @@ TEST_F(ValidationErrorTest, InvalidDefaults) { "foo.proto: Foo.moo: DEFAULT_VALUE: Messages can't have default values.\n" "foo.proto: Foo.corge: DEFAULT_VALUE: Repeated fields can't have default " "values.\n" + "foo.proto: Foo.bytes_default: DEFAULT_VALUE: Invalid escaping in " + "default value.\n" // This ends up being reported later because the error is detected at // cross-linking time. "foo.proto: Foo.mooo: DEFAULT_VALUE: Messages can't have default "