mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
testing: move fuzzers over from OSS-Fuzz
Signed-off-by: AdamKorcz <adam@adalogics.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
36a2dd36a0
commit
93fa093122
39
pkg/tailfile/fuzz_test.go
Normal file
39
pkg/tailfile/fuzz_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
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))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user