Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
encoding/gob: Decode: invalid memory address or nil pointer dereference #6323
gob Decoder.Decode() may crash with the following error: panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x10 pc=0x50ecba] goroutine 1257899 [running]: encoding/gob.catchError(0xc206293498) /usr/local/go/src/pkg/encoding/gob/error.go:38 +0x8d encoding/gob.(*Decoder).decodeValue(0xc2062933c0, 0xc200000012, 0x65fa80, 0xc2061b0bc0, 0x160, ...) /usr/local/go/src/pkg/encoding/gob/decode.go:1228 +0x1ea encoding/gob.(*Decoder).DecodeValue(0xc2062933c0, 0x65fa80, 0xc2061b0bc0, 0x160, 0x0, ...) /usr/local/go/src/pkg/encoding/gob/decoder.go:225 +0x13f encoding/gob.(*Decoder).Decode(0xc2062933c0, 0x65fa80, 0xc2061b0bc0, 0x0, 0x0, ...) /usr/local/go/src/pkg/encoding/gob/decoder.go:202 +0x1c3 I'm currently not able to find exactly which input is causing this, however this crash happens regularly. Using go version go1.1.2 linux/amd64
Finally managed to reproduce the crash, here is a reproducing example: https://gist.github.com/arnaud-lb/1396ea67af6f57ad5efa It is possible that the input is malformed / corrupted.
The input contains a `(type id, encoding of a value)`, where `type id` refers to a type that hasn't been described over the wire. The decoder doesn't handle this, and crashes when trying to access the `wireType` at `dec.wireType[wireId]`, which doesn't exist. I've attached a smaller reproducing example: bug.go The attached diff fixes the problem for me, although it may not handle all cases.