(f *testing.F)
| 13 | ) |
| 14 | |
| 15 | func FuzzEncodingBlocks(f *testing.F) { |
| 16 | fuzz.AddFromZip(f, "testdata/enc_regressions.zip", fuzz.TypeRaw, false) |
| 17 | fuzz.AddFromZip(f, "testdata/fuzz/block-corpus-raw.zip", fuzz.TypeRaw, testing.Short()) |
| 18 | fuzz.AddFromZip(f, "testdata/fuzz/block-corpus-enc.zip", fuzz.TypeGoFuzz, testing.Short()) |
| 19 | |
| 20 | // Fuzzing tweaks: |
| 21 | const ( |
| 22 | // Max input size: |
| 23 | maxSize = 8 << 20 |
| 24 | ) |
| 25 | |
| 26 | f.Fuzz(func(t *testing.T, data []byte) { |
| 27 | if len(data) > maxSize { |
| 28 | return |
| 29 | } |
| 30 | |
| 31 | writeDst := make([]byte, MaxEncodedLen(len(data)), MaxEncodedLen(len(data))+4) |
| 32 | writeDst = append(writeDst, 1, 2, 3, 4) |
| 33 | defer func() { |
| 34 | got := writeDst[MaxEncodedLen(len(data)):] |
| 35 | want := []byte{1, 2, 3, 4} |
| 36 | if !bytes.Equal(got, want) { |
| 37 | t.Fatalf("want %v, got %v - dest modified outside cap", want, got) |
| 38 | } |
| 39 | }() |
| 40 | compDst := writeDst[:MaxEncodedLen(len(data)):MaxEncodedLen(len(data))] // Hard cap |
| 41 | decDst := make([]byte, len(data)) |
| 42 | comp := Encode(compDst, data) |
| 43 | decoded, err := Decode(decDst, comp) |
| 44 | if err != nil { |
| 45 | t.Error(err) |
| 46 | return |
| 47 | } |
| 48 | if !bytes.Equal(data, decoded) { |
| 49 | t.Error("block decoder mismatch") |
| 50 | return |
| 51 | } |
| 52 | if mel := MaxEncodedLen(len(data)); len(comp) > mel { |
| 53 | t.Error(fmt.Errorf("MaxEncodedLen Exceed: input: %d, mel: %d, got %d", len(data), mel, len(comp))) |
| 54 | return |
| 55 | } |
| 56 | comp = EncodeBetter(compDst, data) |
| 57 | decoded, err = Decode(decDst, comp) |
| 58 | if err != nil { |
| 59 | t.Error(err) |
| 60 | return |
| 61 | } |
| 62 | if !bytes.Equal(data, decoded) { |
| 63 | t.Error("block decoder mismatch") |
| 64 | return |
| 65 | } |
| 66 | if mel := MaxEncodedLen(len(data)); len(comp) > mel { |
| 67 | t.Error(fmt.Errorf("MaxEncodedLen Exceed: input: %d, mel: %d, got %d", len(data), mel, len(comp))) |
| 68 | return |
| 69 | } |
| 70 | |
| 71 | comp = EncodeBest(compDst, data) |
| 72 | decoded, err = Decode(decDst, comp) |
nothing calls this directly
no test coverage detected
searching dependent graphs…