From 783a023f6a5dad9376316da8d9025eab9b372e9a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 15 Feb 2024 13:26:33 -0800 Subject: [PATCH] Allow the dispatcher in DescriptorPool to be set to nullptr. Previously, when we call SetRecursiveBuildDispatcher(nullptr), this created a unique_ptr to an AnyInvocable object with a function pointer to a nullptr, which triggers a segmentation fault inside BuildFile. PiperOrigin-RevId: 607435995 --- src/google/protobuf/descriptor.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 199740620b..7d971b35f8 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -2237,9 +2237,13 @@ class PROTOBUF_EXPORT DescriptorPool { // Asynchronous execution is undefined behavior. void SetRecursiveBuildDispatcher( absl::AnyInvocable) const> dispatcher) { - dispatcher_ = std::make_unique< - absl::AnyInvocable) const>>( - std::move(dispatcher)); + if (dispatcher != nullptr) { + dispatcher_ = std::make_unique< + absl::AnyInvocable) const>>( + std::move(dispatcher)); + } else { + dispatcher_.reset(nullptr); + } } #endif // SWIG