fuzzing: improve archive fuzzer

Signed-off-by: AdamKorcz <adam@adalogics.com>
This commit is contained in:
AdamKorcz 2022-10-25 17:21:08 +01:00
parent 47657926af
commit 2e83d885dc

View File

@ -17,9 +17,12 @@
package fuzz package fuzz
import ( import (
"archive/tar"
"bytes" "bytes"
"context" "context"
"io"
"os" "os"
"path"
fuzz "github.com/AdaLogics/go-fuzz-headers" fuzz "github.com/AdaLogics/go-fuzz-headers"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -28,6 +31,7 @@ import (
"github.com/containerd/containerd/content/local" "github.com/containerd/containerd/content/local"
imageArchive "github.com/containerd/containerd/images/archive" imageArchive "github.com/containerd/containerd/images/archive"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
) )
// FuzzApply implements a fuzzer that applies // FuzzApply implements a fuzzer that applies
@ -73,6 +77,31 @@ func FuzzImportIndex(data []byte) int {
} }
ctx := context.Background() ctx := context.Background()
r := bytes.NewReader(tarBytes) 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-") tmpdir, err := os.MkdirTemp("", "fuzzing-")
if err != nil { if err != nil {
return 0 return 0