2019-09-06 18:12:46 +00:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-07-30 14:28:58 -07:00
|
|
|
//go:build gofuzz
|
2019-09-06 18:12:46 +00:00
|
|
|
|
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Fuzz(data []byte) (score int) {
|
2022-02-11 14:53:56 -08:00
|
|
|
for _, ctor := range []func() any{
|
|
|
|
func() any { return new(any) },
|
|
|
|
func() any { return new(map[string]any) },
|
|
|
|
func() any { return new([]any) },
|
2019-09-06 18:12:46 +00:00
|
|
|
} {
|
|
|
|
v := ctor()
|
|
|
|
err := Unmarshal(data, v)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
score = 1
|
|
|
|
|
|
|
|
m, err := Marshal(v)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("v=%#v\n", v)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
u := ctor()
|
|
|
|
err = Unmarshal(m, u)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("v=%#v\n", v)
|
2019-09-12 23:22:53 +00:00
|
|
|
fmt.Printf("m=%s\n", m)
|
2019-09-06 18:12:46 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|