Skip to content

Commit e495a2d

Browse files
umlublinFiloSottile
authored andcommitted
cryptobyte: fix parsing of large ASN.1 OIDs
Fixes golang/go#49678 Change-Id: If8a40e25edd810a66165ab78dd68d9b7fc2699f8 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/365674 Reviewed-by: Filippo Valsorda <[email protected]> Run-TryBot: Filippo Valsorda <[email protected]> Trust: Alex Rakoczy <[email protected]> Trust: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 4570a08 commit e495a2d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cryptobyte/asn1.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,12 @@ func (s *String) ReadASN1Enum(out *int) bool {
407407
func (s *String) readBase128Int(out *int) bool {
408408
ret := 0
409409
for i := 0; len(*s) > 0; i++ {
410-
if i == 4 {
410+
if i == 5 {
411+
return false
412+
}
413+
// Avoid overflowing int on a 32-bit platform.
414+
// We don't want different behavior based on the architecture.
415+
if ret >= 1<<(31-7) {
411416
return false
412417
}
413418
ret <<= 7

cryptobyte/asn1_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ func TestASN1ObjectIdentifier(t *testing.T) {
247247
{[]byte{6, 4, 85, 0x02, 0xc0, 0x00}, true, []int{2, 5, 2, 0x2000}},
248248
{[]byte{6, 3, 0x81, 0x34, 0x03}, true, []int{2, 100, 3}},
249249
{[]byte{6, 7, 85, 0x02, 0xc0, 0x80, 0x80, 0x80, 0x80}, false, []int{}},
250+
{[]byte{6, 7, 85, 0x02, 0x85, 0xc7, 0xcc, 0xfb, 0x01}, true, []int{2, 5, 2, 1492336001}},
251+
{[]byte{6, 7, 0x55, 0x02, 0x87, 0xff, 0xff, 0xff, 0x7f}, true, []int{2, 5, 2, 2147483647}}, // 2**31-1
252+
{[]byte{6, 7, 0x55, 0x02, 0x88, 0x80, 0x80, 0x80, 0x00}, false, []int{}}, // 2**31
250253
}
251254

252255
for i, test := range testData {

0 commit comments

Comments
 (0)