fuzzing: improve archive fuzzer
Signed-off-by: AdamKorcz <adam@adalogics.com>
This commit is contained in:
parent
47657926af
commit
2e83d885dc
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user