MCPcopy
hub / github.com/containerd/containerd / FuzzImportIndex

Function FuzzImportIndex

contrib/fuzz/archive_fuzz_test.go:66–138  ·  view source on GitHub ↗

FuzzImportIndex implements a fuzzer that targets archive.ImportIndex()

(f *testing.F)

Source from the content-addressed store, hash-verified

64// FuzzImportIndex implements a fuzzer
65// that targets archive.ImportIndex()
66func FuzzImportIndex(f *testing.F) {
67 f.Fuzz(func(t *testing.T, data []byte) {
68 f := fuzz.NewConsumer(data)
69 tarBytes, err := f.TarBytes()
70 if err != nil {
71 return
72 }
73 var r *bytes.Reader
74 ctx := context.Background()
75 r = bytes.NewReader(tarBytes)
76 shouldRequireLayoutOrManifest, err := f.GetBool()
77 if err != nil {
78 return
79 }
80 if shouldRequireLayoutOrManifest {
81 hasLayoutOrManifest := false
82 tr := tar.NewReader(r)
83 for {
84 hdr, err := tr.Next()
85 if err == io.EOF {
86 break
87 }
88 if err != nil {
89 return
90 }
91 hdrName := path.Clean(hdr.Name)
92 switch hdrName {
93 case ocispec.ImageLayoutFile, "manifest.json":
94 hasLayoutOrManifest = true
95 }
96 }
97 if !hasLayoutOrManifest {
98 var buf bytes.Buffer
99 tw := tar.NewWriter(&buf)
100 defer tw.Close()
101 tr := tar.NewReader(r)
102 for {
103 hdr, err := tr.Next()
104 if err == io.EOF {
105 break
106 }
107 if err != nil {
108 return
109 }
110 fileContents, err := io.ReadAll(tr)
111 if err != nil {
112 return
113 }
114 tw.WriteHeader(hdr)
115 tw.Write(fileContents)
116 }
117 manifestFileContents, err := f.GetBytes()
118 if err != nil {
119 return
120 }
121 tw.WriteHeader(&tar.Header{
122 Name: "manifest.json",
123 Mode: 0644,

Callers

nothing calls this directly

Calls 4

WriteMethod · 0.95
NewStoreFunction · 0.92
CloseMethod · 0.65
BytesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…