internal/fuzz/wire: add test, seed corpus

Test the fuzzer with a minimal seed corpus. (Currently one file
containing a valid TestAllTypes messge with most fields set.)

Change-Id: I8dcec4e26f1e8374993cc3a4bef0496f36cccd41
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/201639
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/internal/fuzz/wire/corpus/093039684b75b1f06f7a5aeb81b61fb9b6821c8a b/internal/fuzz/wire/corpus/093039684b75b1f06f7a5aeb81b61fb9b6821c8a
new file mode 100644
index 0000000..cf599f2
--- /dev/null
+++ b/internal/fuzz/wire/corpus/093039684b75b1f06f7a5aeb81b61fb9b6821c8a
Binary files differ
diff --git a/internal/fuzz/wire/fuzz.go b/internal/fuzz/wire/fuzz.go
index c0da64a..1d0ae51 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 @@
 	"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 @@
 	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 @@
 		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 0000000..40a510a
--- /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)
+		})
+	}
+}