golang/go

crypto/x509: input not full blocks

dvyukov opened this issue · 1 comments

The following program crashes with the panic:

package main

import (
    "bytes"
    "crypto/x509"
    "encoding/gob"
    "encoding/pem"
)

func main() {
    data := []byte("3\xff\x81\x03\x01\x01\x0500000\x01\xff0\x00\x01\x03\x01\x04" +
        "0000\x01\f\x00\x01\aHeaders\x01\xff\x84\x00" +
        "\x01\x05Bytes\x01\n\x00\x00\x00!\xff\x83\x04\x01\x01\x110" +
        "0000000000000000\x01\xff0\x00" +
        "\x01\f\x01\f\x00\x00L\xff\x82\x01\x03000\x01\x02\t000" +
        "000000\v00000000000\bD" +
        "EK-Info\x18DES-CBC,0000" +
        "000000000000\x01\x010\x000000" +
        "000")
    var b pem.Block
    err := gob.NewDecoder(bytes.NewReader(data)).Decode(&b)
    if err != nil {
        return
    }
    _, err = x509.DecryptPEMBlock(&b, []byte("pass"))
    if err != nil {
        return
    }
}
panic: crypto/cipher: input not full blocks

goroutine 1 [running]:
crypto/cipher.(*cbcDecrypter).CryptBlocks(0xc2080149b0, 0xc20800b180, 0x1, 0x1, 0xc20800b130, 0x1, 0x1)
    src/crypto/cipher/cbc.go:92 +0xa6
crypto/x509.DecryptPEMBlock(0xc208016c90, 0xc20800b140, 0x4, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0)
    src/crypto/x509/pem_decrypt.go:149 +0x879
main.main()
    pem.go:25 +0x47b

go version devel +6a34206 Sun Jun 14 17:55:53 2015 +0000 linux/amd64

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