Fuzzing: Add two more fuzzers

Signed-off-by: AdamKorcz <adam@adalogics.com>
This commit is contained in:
AdamKorcz
2021-08-03 11:32:19 +01:00
parent 7d4891783a
commit 41a04246f4
3 changed files with 169 additions and 1 deletions

View File

@@ -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
}