golang/protobuf

Invalid map is successfully decoded

dvyukov opened this issue · 1 comments

The following program crashes with the panic:

package main

import (
    pb "github.com/dvyukov/go-fuzz/examples/protobuf/pb"
    "github.com/golang/protobuf/proto"
)

func main() {
    data := []byte("\n\x02\n\x00")
    v := new(pb.M24)
    err := proto.Unmarshal(data, v)
    if err != nil {
        return
    }
    _, err = proto.Marshal(v)
    if err != nil {
        panic(err)
    }
}
panic: proto: map has nil element

The proto used is:

message M24 {
  map<string, M2> f = 1;
}

The message should either be successfully encoded or not decoded.

on commit 34a5f24

This appears to be successfully encoded now :)

$ rm -rf $GOPATH/src/github.com/{dvyukov/go-fuzz,golang/protobuf}
$ cat <<EOF > main.go
package main

import (
    pb "github.com/dvyukov/go-fuzz/examples/protobuf/pb"
    "github.com/golang/protobuf/proto"
)

func main() {
    data := []byte("\n\x02\n\x00")
    v := new(pb.M24)
    err := proto.Unmarshal(data, v)
    if err != nil {
        return
    }
    _, err = proto.Marshal(v)
    if err != nil {
        panic(err)
    }
}
EOF
$ go get .
$ go build && ./golang-protobuf-issue-34
$ echo $?
0