MCPcopy
hub / github.com/containerd/containerd / FuzzContentStore

Function FuzzContentStore

contrib/fuzz/metadata_fuzz_test.go:327–433  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

325}
326
327func FuzzContentStore(f *testing.F) {
328 f.Fuzz(func(t *testing.T, data []byte) {
329 const (
330 opInfo = "Info"
331 opUpdate = "Update"
332 opWalk = "Walk"
333 opDelete = "Delete"
334 opListStatuses = "ListStatuses"
335 opStatus = "Status"
336 opAbort = "Abort"
337 opCommit = "Commit"
338 )
339 contentStoreOptions := []string{opInfo, opUpdate, opWalk, opDelete, opListStatuses, opStatus, opAbort, opCommit}
340 ctx, db, cancel, err := testDB(t)
341 defer cancel()
342 if err != nil {
343 return
344 }
345
346 cs := db.ContentStore()
347 f := fuzz.NewConsumer(data)
348 noOfOperations, err := f.GetInt()
349 if err != nil {
350 return
351 }
352 maxOperations := 50
353 for i := 0; i < noOfOperations%maxOperations; i++ {
354 opType, err := f.GetInt()
355 if err != nil {
356 return
357 }
358 switch contentStoreOptions[opType%len(contentStoreOptions)] {
359 case opInfo:
360 blob, err := f.GetBytes()
361 if err != nil {
362 return
363 }
364 dgst := digest.FromBytes(blob)
365 err = dgst.Validate()
366 if err != nil {
367 return
368 }
369 _, _ = cs.Info(ctx, dgst)
370 case opUpdate:
371 info := content.Info{}
372 err = f.GenerateStruct(&info)
373 if err != nil {
374 return
375 }
376 _, _ = cs.Update(ctx, info)
377 case opWalk:
378 walkFn := func(info content.Info) error {
379 return nil
380 }
381 _ = cs.Walk(ctx, walkFn)
382 case opDelete:
383 blob, err := f.GetBytes()
384 if err != nil {

Callers

nothing calls this directly

Calls 15

WithDescriptorFunction · 0.92
WithRefFunction · 0.92
testDBFunction · 0.70
ContentStoreMethod · 0.65
InfoMethod · 0.65
UpdateMethod · 0.65
WalkMethod · 0.65
DeleteMethod · 0.65
ListStatusesMethod · 0.65
StatusMethod · 0.65
AbortMethod · 0.65
WriterMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…