From 3631e225f84b61597edd1a12f6611b3dc532f72d Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 19 Jun 2019 10:21:17 -0700 Subject: [PATCH] reflect/protodesc: don't panic on nil Resolver The change to make protodesc.NewFile take an interface rather than a concrete type means that NewFile(f, nil) now causes a panic. (A nil *protoregistry.Files is valid.) Fix this panic by using a default, empty registry when NewFile's second parameter is nil. Change-Id: I70a1f0759e7ea5b57fba5b6123ee85188f4d560c Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/182979 Reviewed-by: Joe Tsai --- reflect/protodesc/protodesc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/reflect/protodesc/protodesc.go b/reflect/protodesc/protodesc.go index 187eb8ba..f6609088 100644 --- a/reflect/protodesc/protodesc.go +++ b/reflect/protodesc/protodesc.go @@ -13,6 +13,7 @@ import ( "google.golang.org/protobuf/internal/errors" "google.golang.org/protobuf/internal/prototype" "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/types/descriptorpb" ) @@ -53,6 +54,9 @@ type Resolver interface { // The caller must relinquish full ownership of the input fd and must not // access or mutate any fields. func NewFile(fd *descriptorpb.FileDescriptorProto, r Resolver) (protoreflect.FileDescriptor, error) { + if r == nil { + r = (*protoregistry.Files)(nil) // empty resolver + } var f prototype.File switch fd.GetSyntax() { case "proto2", "":