1
1
mirror of https://github.com/wader/fq.git synced 2024-11-26 10:33:53 +03:00
fq/dev/fuzzbytes.go
Mattias Wadman 42debe5871 dev,doc,make: Cleanup makefile and have proper targets for *.md and *.svg
Update format dev docs to only generate README.md and doc/foramts.md to not
cause formats.svg conflicts.
2022-12-04 12:37:10 +01:00

33 lines
655 B
Go

// tool to convert go fuzz input files to bytes
// Usage: cat format/testdata/fuzz/FuzzFormats/144bde49b40c90fd05d302ec90b6ddb2b6d6aea553bad520a8b954797e40fe72 | go run dev/fuzzbytes.go | go run .
package main
import (
"bytes"
"io"
"os"
"strconv"
)
func main() {
bs, err := io.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
// Input looks like this:
// go test fuzz v1
// []byte("...")
prefix := []byte("[]byte(")
start := bytes.Index(bs, prefix) + len(prefix)
end := len(bs) - 2
s, err := strconv.Unquote(string(bs[start:end]))
if err != nil {
panic(err)
}
if _, err := os.Stdout.Write([]byte(s)); err != nil {
panic(err)
}
}