golang/protobuf

call of reflect.Value.Interface on zero Value in MarshalText

dvyukov opened this issue · 0 comments

The following program crashes with a panic:

package main

import (
    "github.com/golang/protobuf/proto"
    "io/ioutil"
    pb "protorepro/pb"
)

func main() {
    proto.MarshalText(ioutil.Discard, &pb.M2{F: map[string]*pb.M1{"": nil}})
}
panic: reflect: call of reflect.Value.Interface on zero Value

goroutine 1 [running]:
runtime.gopanic(0x52e860, 0xc20800e4a0)
    src/runtime/panic.go:461 +0x401 fp=0xc2080415a0 sp=0xc208041520
reflect.valueInterface(0x0, 0x0, 0x0, 0x542801, 0x0, 0x0)
    src/reflect/value.go:906 +0x82 fp=0xc2080415f8 sp=0xc2080415a0
reflect.Value.Interface(0x0, 0x0, 0x0, 0x0, 0x0)
    src/reflect/value.go:901 +0x4f fp=0xc208041630 sp=0xc2080415f8
github.com/golang/protobuf/proto.writeAny(0xc20800e400, 0x0, 0x0, 0x0, 0xc208070240, 0x0, 0x0)
    src/github.com/golang/protobuf/proto/text.go:465 +0x632 fp=0xc2080417f8 sp=0xc208041630
github.com/golang/protobuf/proto.writeStruct(0xc20800e400, 0x536380, 0xc20800e3e0, 0xd9, 0x0, 0x0)
    src/github.com/golang/protobuf/proto/text.go:295 +0xf89 fp=0xc208041da0 sp=0xc2080417f8
github.com/golang/protobuf/proto.marshalText(0x7f558bbca1e8, 0xc20800a5f0, 0x7f558bbca210, 0xc20800e3e0, 0x62c100, 0x0, 0x0)
    src/github.com/golang/protobuf/proto/text.go:759 +0x440 fp=0xc208041ee0 sp=0xc208041da0
github.com/golang/protobuf/proto.MarshalText(0x7f558bbca1e8, 0xc20800a5f0, 0x7f558bbca210, 0xc20800e3e0, 0x0, 0x0)
    src/github.com/golang/protobuf/proto/text.go:771 +0x57 fp=0xc208041f20 sp=0xc208041ee0
main.main()
    protorepro.go:10 +0x129 fp=0xc208041f90 sp=0xc208041f20

The proto used is:

syntax = "proto2";

package example;

message M1 {
  optional uint32 f = 1;
}

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

golang/protobuf is on 16256d3
protobuf is on fe7b566