mirror of
https://github.com/FiloSottile/age.git
synced 2026-01-03 19:03:57 +00:00
Developed live over 6 hours of streaming on Twitch. https://twitter.com/FiloSottile/status/1180875486911766528
36 lines
588 B
Go
36 lines
588 B
Go
// +build gofuzz
|
|
|
|
package format
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func Fuzz(data []byte) int {
|
|
h, payload, err := Parse(bytes.NewReader(data))
|
|
if err != nil {
|
|
if h != nil {
|
|
panic("h != nil on error")
|
|
}
|
|
if payload != nil {
|
|
panic("payload != nil on error")
|
|
}
|
|
return 0
|
|
}
|
|
w := &bytes.Buffer{}
|
|
if err := h.Marshal(w); err != nil {
|
|
panic(err)
|
|
}
|
|
if _, err := io.Copy(w, payload); err != nil {
|
|
panic(err)
|
|
}
|
|
if !bytes.Equal(w.Bytes(), data) {
|
|
fmt.Fprintf(os.Stderr, "%s\n%q\n%q\n\n", w, data, w)
|
|
panic("Marshal output different from input")
|
|
}
|
|
return 1
|
|
}
|