Skip to content

Commit c9ad32b

Browse files
callthingsoffgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
1 parent 7d114b5 commit c9ad32b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/encoding/asn1/asn1.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
702702
if !t.isCompound && t.class == ClassUniversal {
703703
innerBytes := bytes[offset : offset+t.length]
704704
switch t.tag {
705+
case TagBoolean:
706+
result, err = parseBool(innerBytes)
705707
case TagPrintableString:
706708
result, err = parsePrintableString(innerBytes)
707709
case TagNumericString:

src/encoding/asn1/marshal_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,26 @@ func TestIssue11130(t *testing.T) {
311311
}
312312
}
313313

314+
func TestIssue68241(t *testing.T) {
315+
for i, want := range []any{false, true} {
316+
data, err := Marshal(want)
317+
if err != nil {
318+
t.Errorf("cannot Marshal: %v", err)
319+
return
320+
}
321+
322+
var got any
323+
_, err = Unmarshal(data, &got)
324+
if err != nil {
325+
t.Errorf("cannot Unmarshal: %v", err)
326+
return
327+
}
328+
if !reflect.DeepEqual(got, want) {
329+
t.Errorf("#%d Unmarshal, got: %v, want: %v", i, got, want)
330+
}
331+
}
332+
}
333+
314334
func BenchmarkMarshal(b *testing.B) {
315335
b.ReportAllocs()
316336

0 commit comments

Comments
 (0)