1
0
mirror of https://github.com/golang/go synced 2024-11-25 07:07:57 -07:00

encoding/asn1: unmarshal bool values correctly dealing with the ANY type

Fixes #68241

Change-Id: I1ee81aa50c2f39f535ad27309e855f19acb2f2ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/595796
Auto-Submit: Roland Shoemaker <roland@golang.org>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
This commit is contained in:
Jes Cok 2024-06-30 02:46:12 +08:00 committed by Gopher Robot
parent 7d114b5b71
commit c9ad32bd9f
2 changed files with 22 additions and 0 deletions

View File

@ -702,6 +702,8 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
if !t.isCompound && t.class == ClassUniversal {
innerBytes := bytes[offset : offset+t.length]
switch t.tag {
case TagBoolean:
result, err = parseBool(innerBytes)
case TagPrintableString:
result, err = parsePrintableString(innerBytes)
case TagNumericString:

View File

@ -311,6 +311,26 @@ func TestIssue11130(t *testing.T) {
}
}
func TestIssue68241(t *testing.T) {
for i, want := range []any{false, true} {
data, err := Marshal(want)
if err != nil {
t.Errorf("cannot Marshal: %v", err)
return
}
var got any
_, err = Unmarshal(data, &got)
if err != nil {
t.Errorf("cannot Unmarshal: %v", err)
return
}
if !reflect.DeepEqual(got, want) {
t.Errorf("#%d Unmarshal, got: %v, want: %v", i, got, want)
}
}
}
func BenchmarkMarshal(b *testing.B) {
b.ReportAllocs()