Fuzzing: Add two more fuzzers
Signed-off-by: AdamKorcz <adam@adalogics.com>
This commit is contained in:
@@ -24,6 +24,8 @@ import (
|
||||
fuzz "github.com/AdaLogics/go-fuzz-headers"
|
||||
|
||||
"github.com/containerd/containerd/archive"
|
||||
"github.com/containerd/containerd/content/local"
|
||||
imageArchive "github.com/containerd/containerd/images/archive"
|
||||
)
|
||||
|
||||
// FuzzApply implements a fuzzer that applies
|
||||
@@ -50,3 +52,25 @@ func FuzzApply(data []byte) int {
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
// FuzzImportIndex implements a fuzzer
|
||||
// that targets archive.ImportIndex()
|
||||
func FuzzImportIndex(data []byte) int {
|
||||
f := fuzz.NewConsumer(data)
|
||||
tarBytes, err := f.TarBytes()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ctx := context.Background()
|
||||
r := bytes.NewReader(tarBytes)
|
||||
tmpdir, err := ioutil.TempDir("", "fuzzing-")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
cs, err := local.NewStore(tmpdir)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
_, _ = imageArchive.ImportIndex(ctx, cs, r)
|
||||
return 1
|
||||
}
|
||||
|
Reference in New Issue
Block a user