nyaruka / phonenumbers

GoLang port of Google's libphonenumber library
MIT License
1.25k stars 148 forks source link

panic: proto: nil destination in phonenumbers.FormatInOriginalFormat #39

Closed janh closed 5 years ago

janh commented 5 years ago

FormatInOriginalFormat panics in some cases:

panic: proto: nil destination

goroutine 1 [running]:
github.com/golang/protobuf/proto.Merge(0x757080, 0x0, 0x757080, 0xc000231920)
    /home/jan/Entwicklung/go/src/github.com/golang/protobuf/proto/clone.go:86 +0x71b
github.com/nyaruka/phonenumbers.FormatInOriginalFormat(0xc0002efef0, 0x5e6766, 0x2, 0x2, 0x101)
    /home/jan/Entwicklung/go/src/github.com/nyaruka/phonenumbers/phonenumbers.go:1527 +0x4bb
main.main()
    /home/jan/test/main.go:13 +0xe0
exit status 2

This can be reproduced with the following sample code:

package main

import (
    "fmt"
    "github.com/nyaruka/phonenumbers"
)

func main() {
    number, err := phonenumbers.ParseAndKeepRawInput("0987654321", "DE")
    if err != nil {
        panic(err)
    }
    formatted := phonenumbers.FormatInOriginalFormat(number, "DE")
    fmt.Println(formatted)
}

Similar to #16, this is because proto.Merge is called with a nil dst here: https://github.com/nyaruka/phonenumbers/blob/ce4687a3c3670db386ad061c6644aad33800d8f4/phonenumbers.go#L1526-L1527

The same also occurs at two other places: https://github.com/nyaruka/phonenumbers/blob/ce4687a3c3670db386ad061c6644aad33800d8f4/phonenumbers.go#L1648-L1649 https://github.com/nyaruka/phonenumbers/blob/ce4687a3c3670db386ad061c6644aad33800d8f4/phonenumbers.go#L2472-L2473

nicpottier commented 5 years ago

Thanks for the report. I'm a bit busy right now but if somebody wants to put together a PR I'm happy to take a look. Otherwise will likely have a bit of time next week to take a look.