9b890cf9c5
* go.mod: bump minimum and language to 1.21
CI only tests Go 1.21 and 1.22, and older versions of Go are no longer
getting any bug or security fixes, so advertise that we only support
Go 1.21 or later via go.mod.
While here, ensure the module is tidy and resolve deprecation warnings,
and remove now-unnecessary Go version build tags.
* replace sort.Slice with slices.SortFunc
The latter is more efficient, and allocates less, since sort.Slice
needs to go through sort.Interface which causes allocations.
goos: linux
goarch: amd64
pkg: github.com/pelletier/go-toml/v2/benchmark
cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics
│ old │ new │
│ sec/op │ sec/op vs base │
Marshal/HugoFrontMatter-8 7.612µ ± 1% 6.730µ ± 1% -11.59% (p=0.002 n=6)
│ old │ new │
│ B/s │ B/s vs base │
Marshal/HugoFrontMatter-8 65.52Mi ± 1% 74.11Mi ± 1% +13.11% (p=0.002 n=6)
│ old │ new │
│ B/op │ B/op vs base │
Marshal/HugoFrontMatter-8 5.672Ki ± 0% 5.266Ki ± 0% -7.16% (p=0.002 n=6)
│ old │ new │
│ allocs/op │ allocs/op vs base │
Marshal/HugoFrontMatter-8 85.00 ± 0% 73.00 ± 0% -14.12% (p=0.002 n=6)
43 lines
663 B
Go
43 lines
663 B
Go
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
|
|
}
|