ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.85k stars 295 forks source link

SIGSEGV from crypto.tls.Conn.Handshake(...) performing msgpack rpc #356

Closed joseroberto closed 3 years ago

joseroberto commented 3 years ago

It happens under heavy load situations:

Version: github.com/ugorji/go/codec v1.2.4

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x24 pc=0x60e547]
goroutine 12044 [running]:
crypto/tls.(*Conn).Handshake(0x0, 0x0, 0x0)
        /usr/local/go/src/crypto/tls/conn.go:1378 +0x47
crypto/tls.(*Conn).Read(0x0, 0xc006a3e31a, 0x1, 0x1, 0x0, 0x0, 0x0)
        /usr/local/go/src/crypto/tls/conn.go:1263 +0x53
github.com/ugorji/go/codec.(*msgpackSpecRpcCodec).parseCustomHeader(0xc007492230, 0x40fb01, 0xc005f48d00, 0xc005f48d08, 0x1, 0xc005f48cf0)
        /go/pkg/mod/github.com/ugorji/go/codec@v1.2.4/msgpack.go:1149 +0xa7
github.com/ugorji/go/codec.(*msgpackSpecRpcCodec).ReadResponseHeader(0xc007492230, 0xc005f48cf0, 0x0, 0x0)
        /go/pkg/mod/github.com/ugorji/go/codec@v1.2.4/msgpack.go:1121 +0x49
net/rpc.(*Client).input(0xc00688d020)
        /usr/local/go/src/net/rpc/client.go:109 +0xa8
created by net/rpc.NewClientWithCodec
        /usr/local/go/src/net/rpc/client.go:206 +0x89
ugorji commented 3 years ago

This bug is weird, and it doesn't look like I can do anything with it.

The code in question:

    var ba [1]byte
    var n int
    for {
        n, err = c.r.Read(ba[:]) // line in question
        if err != nil {
            return
        }
        if n == 1 {
            break
        }
    }

The actual codebase resulting in an error is from go's stdlib: crypto/tls/conn.go:1378 i.e. a call to crypto/tls.(*Conn).Handshake(...)

This is outside of codec, and so this doesn't look like na issue with go-codec library.

I think you should raise an issue with the go's crypto library where the error was seen.