From 851ca21f59a43257ef45836cc550bcef8a4eda0c Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Thu, 6 Jun 2024 15:39:32 -0700 Subject: [PATCH] Make sure the generated pool is initialized before building any other pools. Because we parse options into the generated pool for *all* descriptor pool builds, it's important that it's properly initialized. Notably, if the C++ feature extensions haven't been registered we can end up with crashes from files that specify them. PiperOrigin-RevId: 641043996 --- src/google/protobuf/descriptor.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index a8ec49f26a..f668ae2522 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -5752,6 +5752,14 @@ static void PlanAllocationSize(const FileDescriptorProto& proto, const FileDescriptor* DescriptorBuilder::BuildFile( const FileDescriptorProto& proto) { + // Ensure the generated pool has been lazily initialized. This is most + // important for protos that use C++-specific features, since that extension + // is only registered lazily and we always parse options into the generated + // pool. + if (pool_ != DescriptorPool::internal_generated_pool()) { + DescriptorPool::generated_pool(); + } + filename_ = proto.name(); // Check if the file already exists and is identical to the one being built.