Merge pull request #7588 from AdamKorcz/fuzz1

This commit is contained in:
Samuel Karp 2022-10-28 11:22:28 -07:00 committed by GitHub
commit 8167751f56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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