-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reflect/protodesc: fix panic when working with dynamicpb
Thanks to Joshua Humphries and Edward McFarlane for the excellent bug report, reproducer and fix suggestion! Fixes golang/protobuf#1669 Change-Id: I03df76f789e6e11b53396396a1f6b58bb3fb840b Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/642575 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Chressie Himpel <[email protected]>
- Loading branch information
1 parent
2f60868
commit 7cbd915
Showing
2 changed files
with
68 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2025 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package protodesc | ||
|
||
import ( | ||
"testing" | ||
|
||
"google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/reflect/protoreflect" | ||
"google.golang.org/protobuf/types/descriptorpb" | ||
"google.golang.org/protobuf/types/dynamicpb" | ||
"google.golang.org/protobuf/types/gofeaturespb" | ||
) | ||
|
||
func TestGoFeaturesDynamic(t *testing.T) { | ||
md := (*gofeaturespb.GoFeatures)(nil).ProtoReflect().Descriptor() | ||
gf := dynamicpb.NewMessage(md) | ||
opaque := protoreflect.ValueOfEnum(gofeaturespb.GoFeatures_API_OPAQUE.Number()) | ||
gf.Set(md.Fields().ByName("api_level"), opaque) | ||
featureSet := &descriptorpb.FeatureSet{} | ||
dynamicExt := dynamicpb.NewExtensionType(gofeaturespb.E_Go.TypeDescriptor().Descriptor()) | ||
proto.SetExtension(featureSet, dynamicExt, gf) | ||
|
||
fd := &descriptorpb.FileDescriptorProto{ | ||
Name: proto.String("a.proto"), | ||
Dependency: []string{ | ||
"google/protobuf/go_features.proto", | ||
}, | ||
Edition: descriptorpb.Edition_EDITION_2023.Enum(), | ||
Syntax: proto.String("editions"), | ||
Options: &descriptorpb.FileOptions{ | ||
Features: featureSet, | ||
}, | ||
} | ||
fds := &descriptorpb.FileDescriptorSet{ | ||
File: []*descriptorpb.FileDescriptorProto{ | ||
ToFileDescriptorProto(descriptorpb.File_google_protobuf_descriptor_proto), | ||
ToFileDescriptorProto(gofeaturespb.File_google_protobuf_go_features_proto), | ||
fd, | ||
}, | ||
} | ||
if _, err := NewFiles(fds); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |