From a38e4ec203465fadfe07626f71b88d81cf653d8c Mon Sep 17 00:00:00 2001 From: hitzhangjie Date: Thu, 2 Mar 2023 19:30:46 +0800 Subject: [PATCH] fix/fuzz: output int32(v)/rune(q) in failing log When fuzz testing outputs failing input into testdata/, it needs to marshal the input, In go, int32 and rune are the same datatype, so it cannot differentiate the two types in typeswitch. Before, when the data is a valid unicode point, it will outputs `rune(%q)` in the log, but the real datatype maybe a int32. In this case, we have to query the ASCII or unicode table to get the int32 value. It's inconvenient. So, here we output `int32(%v)/rune(%q)` to solve this. close #58824 --- src/internal/fuzz/encoding.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/internal/fuzz/encoding.go b/src/internal/fuzz/encoding.go index 270ef7a1a3..b60bd73bdd 100644 --- a/src/internal/fuzz/encoding.go +++ b/src/internal/fuzz/encoding.go @@ -81,7 +81,7 @@ func marshalCorpusFile(vals ...any) []byte { // We arbitrarily draw the line at UTF-8 validity, which biases toward the // "rune" interpretation. (However, we accept either format as input.) if utf8.ValidRune(t) { - fmt.Fprintf(b, "rune(%q)\n", t) + fmt.Fprintf(b, "int32(%v)/rune(%q)\n", t, t) } else { fmt.Fprintf(b, "int32(%v)\n", t) } @@ -117,6 +117,12 @@ func unmarshalCorpusFile(b []byte) ([]any, error) { if len(line) == 0 { continue } + if bytes.HasPrefix(line, []byte("int32")) || + bytes.HasPrefix(line, []byte("rune")) { + if idx := bytes.IndexByte(line, '/'); idx != -1 { + line = line[:idx] + } + } v, err := parseCorpusValue(line) if err != nil { return nil, fmt.Errorf("malformed line %q: %v", line, err)