diff --git a/contrib/fuzz/archive_fuzzer.go b/contrib/fuzz/archive_fuzzer.go index 941467b7e..233513950 100644 --- a/contrib/fuzz/archive_fuzzer.go +++ b/contrib/fuzz/archive_fuzzer.go @@ -17,9 +17,12 @@ package fuzz import ( + "archive/tar" "bytes" "context" + "io" "os" + "path" fuzz "github.com/AdaLogics/go-fuzz-headers" "github.com/sirupsen/logrus" @@ -28,6 +31,7 @@ import ( "github.com/containerd/containerd/content/local" imageArchive "github.com/containerd/containerd/images/archive" "github.com/containerd/containerd/log" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) // FuzzApply implements a fuzzer that applies @@ -73,6 +77,31 @@ func FuzzImportIndex(data []byte) int { } ctx := context.Background() r := bytes.NewReader(tarBytes) + shouldRequireLayoutOrManifest, err := f.GetBool() + if err != nil { + return 0 + } + if shouldRequireLayoutOrManifest { + tr := tar.NewReader(r) + for { + hdr, err := tr.Next() + if err == io.EOF { + break + } + if err != nil { + return 0 + } + hdrName := path.Clean(hdr.Name) + switch hdrName { + case ocispec.ImageLayoutFile: + break + case "manifest.json": + break + default: + return 0 + } + } + } tmpdir, err := os.MkdirTemp("", "fuzzing-") if err != nil { return 0