Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid map is successfully decoded #34

Closed
dvyukov opened this issue Jun 7, 2015 · 1 comment
Closed

Invalid map is successfully decoded #34

dvyukov opened this issue Jun 7, 2015 · 1 comment

Comments

@dvyukov
Copy link
Member

dvyukov commented Jun 7, 2015

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

@JeffPaine
Copy link

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

@dsnet dsnet closed this as completed Feb 5, 2018
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants