golang/go

crypto/x509: division by zero

dvyukov opened this issue · 2 comments

This is a regression from 1.4.2.

The following program crashes with the panic:

package main

import "crypto/x509"

func main() {
    data := []byte("0\x16\x02\x00\x02\x02\u007f\x00\x02\x0200\x02\x0200\x02\x02\x00\x01\x02\x02\u007f\x00")
    x509.ParsePKCS1PrivateKey(data)
}
panic: division by zero

goroutine 1 [running]:
math/big.nat.div(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc208016750, 0x1, 0x5, 0xc208016780, ...)
    src/math/big/nat.go:529 +0xc0
math/big.(*Int).QuoRem(0xc208089bd8, 0xc208089d10, 0xc208089cf0, 0xc208089d30, 0x466a57, 0xc208016780)
    src/math/big/int.go:227 +0xe6
math/big.(*Int).Mod(0xc208089d30, 0xc208089d10, 0xc208089cf0, 0xc208089cf0)
    src/math/big/int.go:258 +0x149
crypto/rsa.(*PrivateKey).Validate(0xc20801e180, 0x0, 0x0)
    src/crypto/rsa/rsa.go:165 +0x3c5
crypto/x509.ParsePKCS1PrivateKey(0xc208010580, 0x18, 0x20, 0xc20801e180, 0x0, 0x0)
    src/crypto/x509/pkcs1.go:77 +0x6af
main.main()
    pkcs.go:7 +0x66

go version devel +4105265 Fri Jun 12 15:51:21 2015 +0000 linux/amd64

CL https://golang.org/cl/11065 mentions this issue.

CL https://golang.org/cl/11611 mentions this issue.