diff --git a/internal/fuzz/wire/corpus/093039684b75b1f06f7a5aeb81b61fb9b6821c8a b/internal/fuzz/wire/corpus/093039684b75b1f06f7a5aeb81b61fb9b6821c8a new file mode 100644 index 00000000..cf599f28 Binary files /dev/null and b/internal/fuzz/wire/corpus/093039684b75b1f06f7a5aeb81b61fb9b6821c8a differ diff --git a/internal/fuzz/wire/fuzz.go b/internal/fuzz/wire/fuzz.go index c0da64ac..1d0ae512 100644 --- a/internal/fuzz/wire/fuzz.go +++ b/internal/fuzz/wire/fuzz.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build gofuzz - // Package wire includes a fuzzer for the wire marshaler and unmarshaler. package wire @@ -11,6 +9,7 @@ import ( "google.golang.org/protobuf/proto" testpb "google.golang.org/protobuf/internal/testprotos/test" + test3pb "google.golang.org/protobuf/internal/testprotos/test3" ) // Fuzz is a fuzzer for proto.Marshal and proto.Unmarshal. @@ -18,6 +17,8 @@ func Fuzz(data []byte) int { score := 0 for _, newf := range []func() proto.Message{ func() proto.Message { return &testpb.TestAllTypes{} }, + func() proto.Message { return &testpb.TestAllExtensions{} }, + func() proto.Message { return &test3pb.TestAllTypes{} }, } { m1 := newf() if err := proto.Unmarshal(data, m1); err != nil { @@ -28,6 +29,9 @@ func Fuzz(data []byte) int { if err != nil { panic(err) } + if proto.Size(m1) != len(data1) { + panic("size does not match output") + } m2 := newf() if err := proto.Unmarshal(data1, m2); err != nil { panic(err) diff --git a/internal/fuzz/wire/fuzz_test.go b/internal/fuzz/wire/fuzz_test.go new file mode 100644 index 00000000..40a510ad --- /dev/null +++ b/internal/fuzz/wire/fuzz_test.go @@ -0,0 +1,30 @@ +package wire + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" +) + +func Test(t *testing.T) { + dir, err := os.Open("corpus") + if err != nil { + t.Fatal(err) + } + infos, err := dir.Readdir(0) + if err != nil { + t.Fatal(err) + + } + for _, info := range infos { + name := info.Name() + t.Run(name, func(t *testing.T) { + b, err := ioutil.ReadFile(filepath.Join("corpus", name)) + if err != nil { + t.Fatal(err) + } + Fuzz(b) + }) + } +}