oschwald / maxminddb-golang

MaxMind DB Reader for Go
ISC License
615 stars 101 forks source link

panic: runtime error: index out of range #37

Closed YoungWing closed 7 years ago

YoungWing commented 7 years ago

panic: runtime error: index out of range

goroutine 411988086 [running]: panic(0xa92dc0, 0xc42000a0e0) /usr/local/go/src/runtime/panic.go:500 +0x1a1 github.com/oschwald/maxminddb-golang.(decoder).decodeCtrlData(0xc4202e6020, 0x79d7b07, 0x0, 0x7f267c0650dc, 0x4) /Users/yangrong/go/src/github.com/oschwald/maxminddb-golang/decoder.go:48 +0xbe github.com/oschwald/maxminddb-golang.(decoder).decode(0xc4202e6020, 0x79d7b07, 0xaf1660, 0xc42a377b80, 0x199, 0x199, 0x199, 0xaf1660) /Users/yangrong/go/src/github.com/oschwald/maxminddb-golang/decoder.go:37 +0x39 github.com/oschwald/maxminddb-golang.(decoder).unmarshalPointer(0xc4202e6020, 0x1b, 0x304a, 0xaf1660, 0xc42a377b80, 0x199, 0x199, 0x738732, 0xc4202e6020) /Users/yangrong/go/src/github.com/oschwald/maxminddb-golang/decoder.go:277 +0x86 github.com/oschwald/maxminddb-golang.(decoder).decodeFromType(0xc4202e6020, 0x1, 0x1b, 0x304a, 0xa41de0, 0xc42a377b80, 0x16, 0x7c5c4, 0x0, 0xa41de0) /Users/yangrong/go/src/github.com/oschwald/maxminddb-golang/decoder.go:103 +0x2a8 github.com/oschwald/maxminddb-golang.(decoder).decode(0xc4202e6020, 0x3049, 0xa41de0, 0xc42a377b80, 0x16, 0xc4202e6000, 0xc420d88fec, 0x4) /Users/yangrong/go/src/github.com/oschwald/maxminddb-golang/decoder.go:43 +0xa0 github.com/oschwald/maxminddb-golang.(Reader).Decode(0xc4202e6000, 0x3049, 0xa41de0, 0xc42a377b80, 0x0, 0xc4204737b0) /Users/yangrong/go/src/github.com/oschwald/maxminddb-golang/reader.go:152 +0x13a github.com/oschwald/maxminddb-golang.(Reader).retrieveData(0xc4202e6000, 0x7c5c4, 0xa41de0, 0xc42a377b80, 0x7c5c4, 0x0) /Users/yangrong/go/src/github.com/oschwald/maxminddb-golang/reader.go:236 +0x74 github.com/oschwald/maxminddb-golang.(Reader).Lookup(0xc4202e6000, 0xc420d88fe0, 0x10, 0x10, 0xa41de0, 0xc42a377b80, 0xc, 0xc420d88fe0) /Users/yangrong/go/src/github.com/oschwald/maxminddb-golang/reader.go:114 +0xa6 github.com/oschwald/geoip2-golang.(*Reader).Country(0xc42015a5e0, 0xc420d88fe0, 0x10, 0x10, 0x10, 0xc420d88fd0, 0xd) /Users/yangrong/go/src/github.com/oschwald/geoip2-golang/reader.go:235 +0x1b7

oschwald commented 7 years ago

How do I reproduce this?

oschwald commented 7 years ago

Although it does not excuse the panic, I suspect your database is corrupt. It would be useful to get a copy of the database as well as the lookup that causes this so that I can confirm any fix. I am, however, running go-fuzz against the library in an attempt to find similar issues.

oschwald commented 7 years ago

I suspect this panic on a corrupt database is fixed in greg/fuzz-fixes.

oschwald commented 7 years ago

This panic should now no longer be possible. An error would be returned instead.