55ca4e35e4
This attempts to improve issue types like timeout, slow_unit and speed, as seen in the following oss-fuzz performance report: https://oss-fuzz.com/performance-report/libFuzzer_go-toml_fuzz_toml/libfuzzer_asan_go-toml/2023-05-11
46 lines
733 B
Go
46 lines
733 B
Go
//go:build go1.18 || go1.19 || go1.20
|
|
// +build go1.18 go1.19 go1.20
|
|
|
|
package ossfuzz
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"strings"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
func FuzzToml(data []byte) int {
|
|
if len(data) >= 2048 {
|
|
return 0
|
|
}
|
|
|
|
if strings.Contains(string(data), "nan") {
|
|
return 0
|
|
}
|
|
|
|
var v interface{}
|
|
err := toml.Unmarshal(data, &v)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
|
|
encoded, err := toml.Marshal(v)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("failed to marshal unmarshaled document: %s", err))
|
|
}
|
|
|
|
var v2 interface{}
|
|
err = toml.Unmarshal(encoded, &v2)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("failed round trip: %s", err))
|
|
}
|
|
|
|
if !reflect.DeepEqual(v, v2) {
|
|
panic(fmt.Sprintf("not equal: %#+v %#+v", v, v2))
|
|
}
|
|
|
|
return 1
|
|
}
|