Ensure `FileDescriptor::edition_` is correctly initialized when built from `FileDescriptorProto`

When `DescriptorBuilder::BuildFileImpl` is called, `alloc.AllocateArray` appears to be allocating an uninitialized object. This means every field inside FileDescriptor should be initialized, and edition_ may be ignored if not present. This can then lead to a SEGFAULT later in `FileDescriptor::edition()`, with a check of `edition_ == nullptr ? anti_hyrum_string : *edition_;` potentially dereferencing `edition_` when it's uninitialized.

PiperOrigin-RevId: 549712519
pull/13366/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent 3ee67038e5
commit 61c6b6aee2
  1. 2
      src/google/protobuf/descriptor.cc

@ -5748,6 +5748,8 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
}
if (proto.has_edition()) {
file_->edition_ = alloc.AllocateStrings(proto.edition());
} else {
file_->edition_ = nullptr;
}
result->name_ = alloc.AllocateStrings(proto.name());

Loading…
Cancel
Save