moby/pkg/tailfile/fuzz_test.go
AdamKorcz 93fa093122
testing: move fuzzers over from OSS-Fuzz
Signed-off-by: AdamKorcz <adam@adalogics.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-30 17:31:03 +01:00

39 lines
633 B
Go

package tailfile
import (
"os"
"path/filepath"
"testing"
fuzz "github.com/AdaLogics/go-fuzz-headers"
)
func FuzzTailfile(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
if len(data) < 5 {
return
}
ff := fuzz.NewConsumer(data)
n, err := ff.GetUint64()
if err != nil {
return
}
fileBytes, err := ff.GetBytes()
if err != nil {
return
}
tempDir := t.TempDir()
fil, err := os.Create(filepath.Join(tempDir, "tailFile"))
if err != nil {
return
}
defer fil.Close()
_, err = fil.Write(fileBytes)
if err != nil {
return
}
fil.Seek(0, 0)
_, _ = TailFile(fil, int(n))
})
}