File: fuzzbytes.go

package info (click to toggle)
fq 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 106,624 kB
  • sloc: xml: 2,835; makefile: 250; sh: 241; exp: 57; ansic: 21
file content (32 lines) | stat: -rw-r--r-- 655 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 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)
	}
}