Coverage Report

Created: 2024-10-11 15:22

/src/wuffs/fuzz/c/fuzzlib/fuzzlib.c
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2018 The Wuffs Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6
// option. This file may not be copied, modified, or distributed
7
// except according to those terms.
8
//
9
// SPDX-License-Identifier: Apache-2.0 OR MIT
10
11
#include <inttypes.h>
12
#include <stdio.h>
13
#include <stdlib.h>
14
#include <string.h>
15
16
#ifndef WUFFS_INCLUDE_GUARD
17
#error "Wuffs' .h files need to be included before this file"
18
#endif
19
20
void  //
21
0
intentional_segfault() {
22
0
  static volatile int* ptr = NULL;
23
0
  *ptr = 0;
24
0
}
Unexecuted instantiation: intentional_segfault
Unexecuted instantiation: intentional_segfault()
25
26
static uint32_t  //
27
37.8k
popcount32(uint32_t x) {
28
37.8k
  static const uint8_t table[256] = {
29
37.8k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
37.8k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
37.8k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
37.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
37.8k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
37.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
37.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
37.8k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
37.8k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
37.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
37.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
37.8k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
37.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
37.8k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
37.8k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
37.8k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
37.8k
  };
46
37.8k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
37.8k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
37.8k
}
png_fuzzer.c:popcount32
Line
Count
Source
27
5.73k
popcount32(uint32_t x) {
28
5.73k
  static const uint8_t table[256] = {
29
5.73k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
5.73k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
5.73k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
5.73k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
5.73k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
5.73k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
5.73k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
5.73k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
5.73k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
5.73k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
5.73k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
5.73k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
5.73k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
5.73k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
5.73k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
5.73k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
5.73k
  };
46
5.73k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
5.73k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
5.73k
}
json_fuzzer.cc:popcount32(unsigned int)
Line
Count
Source
27
5.92k
popcount32(uint32_t x) {
28
5.92k
  static const uint8_t table[256] = {
29
5.92k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
5.92k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
5.92k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
5.92k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
5.92k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
5.92k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
5.92k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
5.92k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
5.92k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
5.92k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
5.92k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
5.92k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
5.92k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
5.92k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
5.92k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
5.92k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
5.92k
  };
46
5.92k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
5.92k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
5.92k
}
gif_fuzzer.c:popcount32
Line
Count
Source
27
2.17k
popcount32(uint32_t x) {
28
2.17k
  static const uint8_t table[256] = {
29
2.17k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
2.17k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
2.17k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
2.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
2.17k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
2.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
2.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
2.17k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
2.17k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
2.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
2.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
2.17k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
2.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
2.17k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
2.17k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
2.17k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
2.17k
  };
46
2.17k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
2.17k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
2.17k
}
xz_fuzzer.c:popcount32
Line
Count
Source
27
8.19k
popcount32(uint32_t x) {
28
8.19k
  static const uint8_t table[256] = {
29
8.19k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
8.19k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
8.19k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
8.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
8.19k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
8.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
8.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
8.19k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
8.19k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
8.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
8.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
8.19k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
8.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
8.19k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
8.19k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
8.19k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
8.19k
  };
46
8.19k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
8.19k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
8.19k
}
jpeg_fuzzer.c:popcount32
Line
Count
Source
27
3.76k
popcount32(uint32_t x) {
28
3.76k
  static const uint8_t table[256] = {
29
3.76k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
3.76k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
3.76k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
3.76k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
3.76k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
3.76k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
3.76k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
3.76k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
3.76k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
3.76k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
3.76k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
3.76k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
3.76k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
3.76k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
3.76k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
3.76k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
3.76k
  };
46
3.76k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
3.76k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
3.76k
}
cbor_fuzzer.c:popcount32
Line
Count
Source
27
2.10k
popcount32(uint32_t x) {
28
2.10k
  static const uint8_t table[256] = {
29
2.10k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
2.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
2.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
2.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
2.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
2.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
2.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
2.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
2.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
2.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
2.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
2.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
2.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
2.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
2.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
2.10k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
2.10k
  };
46
2.10k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
2.10k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
2.10k
}
bmp_fuzzer.c:popcount32
Line
Count
Source
27
3.10k
popcount32(uint32_t x) {
28
3.10k
  static const uint8_t table[256] = {
29
3.10k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
3.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
3.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
3.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
3.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
3.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
3.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
3.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
3.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
3.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
3.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
3.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
3.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
3.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
3.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
3.10k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
3.10k
  };
46
3.10k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
3.10k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
3.10k
}
pixel_swizzler_fuzzer.c:popcount32
Line
Count
Source
27
3.19k
popcount32(uint32_t x) {
28
3.19k
  static const uint8_t table[256] = {
29
3.19k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
3.19k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
3.19k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
3.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
3.19k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
3.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
3.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
3.19k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
3.19k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
3.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
3.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
3.19k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
3.19k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
3.19k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
3.19k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
3.19k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
3.19k
  };
46
3.19k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
3.19k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
3.19k
}
zlib_fuzzer.c:popcount32
Line
Count
Source
27
1.34k
popcount32(uint32_t x) {
28
1.34k
  static const uint8_t table[256] = {
29
1.34k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.34k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.34k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.34k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.34k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.34k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.34k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.34k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.34k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.34k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.34k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.34k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.34k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.34k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.34k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.34k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.34k
  };
46
1.34k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.34k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.34k
}
targa_fuzzer.c:popcount32
Line
Count
Source
27
1.13k
popcount32(uint32_t x) {
28
1.13k
  static const uint8_t table[256] = {
29
1.13k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.13k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.13k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.13k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.13k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.13k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.13k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.13k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.13k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.13k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.13k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.13k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.13k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.13k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.13k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.13k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.13k
  };
46
1.13k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.13k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.13k
}
bzip2_fuzzer.c:popcount32
Line
Count
Source
27
1.17k
popcount32(uint32_t x) {
28
1.17k
  static const uint8_t table[256] = {
29
1.17k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.17k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.17k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.17k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.17k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.17k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.17k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.17k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.17k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.17k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.17k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.17k
  };
46
1.17k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.17k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.17k
}
49
50
// jenkins_hash_u32 implements
51
// https://en.wikipedia.org/wiki/Jenkins_hash_function
52
static uint32_t  //
53
75.6k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
75.6k
  uint32_t hash = 0;
55
75.6k
  size_t i = 0;
56
481M
  while (i != size) {
57
481M
    hash += data[i++];
58
481M
    hash += hash << 10;
59
481M
    hash ^= hash >> 6;
60
481M
  }
61
75.6k
  hash += hash << 3;
62
75.6k
  hash ^= hash >> 11;
63
75.6k
  hash += hash << 15;
64
75.6k
  return hash;
65
75.6k
}
png_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
11.4k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
11.4k
  uint32_t hash = 0;
55
11.4k
  size_t i = 0;
56
59.0M
  while (i != size) {
57
59.0M
    hash += data[i++];
58
59.0M
    hash += hash << 10;
59
59.0M
    hash ^= hash >> 6;
60
59.0M
  }
61
11.4k
  hash += hash << 3;
62
11.4k
  hash ^= hash >> 11;
63
11.4k
  hash += hash << 15;
64
11.4k
  return hash;
65
11.4k
}
json_fuzzer.cc:jenkins_hash_u32(unsigned char const*, unsigned long)
Line
Count
Source
53
11.8k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
11.8k
  uint32_t hash = 0;
55
11.8k
  size_t i = 0;
56
127M
  while (i != size) {
57
127M
    hash += data[i++];
58
127M
    hash += hash << 10;
59
127M
    hash ^= hash >> 6;
60
127M
  }
61
11.8k
  hash += hash << 3;
62
11.8k
  hash ^= hash >> 11;
63
11.8k
  hash += hash << 15;
64
11.8k
  return hash;
65
11.8k
}
gif_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
4.34k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
4.34k
  uint32_t hash = 0;
55
4.34k
  size_t i = 0;
56
49.0M
  while (i != size) {
57
49.0M
    hash += data[i++];
58
49.0M
    hash += hash << 10;
59
49.0M
    hash ^= hash >> 6;
60
49.0M
  }
61
4.34k
  hash += hash << 3;
62
4.34k
  hash ^= hash >> 11;
63
4.34k
  hash += hash << 15;
64
4.34k
  return hash;
65
4.34k
}
xz_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
16.3k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
16.3k
  uint32_t hash = 0;
55
16.3k
  size_t i = 0;
56
44.3M
  while (i != size) {
57
44.3M
    hash += data[i++];
58
44.3M
    hash += hash << 10;
59
44.3M
    hash ^= hash >> 6;
60
44.3M
  }
61
16.3k
  hash += hash << 3;
62
16.3k
  hash ^= hash >> 11;
63
16.3k
  hash += hash << 15;
64
16.3k
  return hash;
65
16.3k
}
jpeg_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
7.53k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
7.53k
  uint32_t hash = 0;
55
7.53k
  size_t i = 0;
56
28.0M
  while (i != size) {
57
28.0M
    hash += data[i++];
58
28.0M
    hash += hash << 10;
59
28.0M
    hash ^= hash >> 6;
60
28.0M
  }
61
7.53k
  hash += hash << 3;
62
7.53k
  hash ^= hash >> 11;
63
7.53k
  hash += hash << 15;
64
7.53k
  return hash;
65
7.53k
}
cbor_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
4.20k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
4.20k
  uint32_t hash = 0;
55
4.20k
  size_t i = 0;
56
39.2M
  while (i != size) {
57
39.2M
    hash += data[i++];
58
39.2M
    hash += hash << 10;
59
39.2M
    hash ^= hash >> 6;
60
39.2M
  }
61
4.20k
  hash += hash << 3;
62
4.20k
  hash ^= hash >> 11;
63
4.20k
  hash += hash << 15;
64
4.20k
  return hash;
65
4.20k
}
bmp_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
6.20k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
6.20k
  uint32_t hash = 0;
55
6.20k
  size_t i = 0;
56
56.0M
  while (i != size) {
57
56.0M
    hash += data[i++];
58
56.0M
    hash += hash << 10;
59
56.0M
    hash ^= hash >> 6;
60
56.0M
  }
61
6.20k
  hash += hash << 3;
62
6.20k
  hash ^= hash >> 11;
63
6.20k
  hash += hash << 15;
64
6.20k
  return hash;
65
6.20k
}
pixel_swizzler_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
6.38k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
6.38k
  uint32_t hash = 0;
55
6.38k
  size_t i = 0;
56
23.6M
  while (i != size) {
57
23.6M
    hash += data[i++];
58
23.6M
    hash += hash << 10;
59
23.6M
    hash ^= hash >> 6;
60
23.6M
  }
61
6.38k
  hash += hash << 3;
62
6.38k
  hash ^= hash >> 11;
63
6.38k
  hash += hash << 15;
64
6.38k
  return hash;
65
6.38k
}
zlib_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.69k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.69k
  uint32_t hash = 0;
55
2.69k
  size_t i = 0;
56
19.3M
  while (i != size) {
57
19.3M
    hash += data[i++];
58
19.3M
    hash += hash << 10;
59
19.3M
    hash ^= hash >> 6;
60
19.3M
  }
61
2.69k
  hash += hash << 3;
62
2.69k
  hash ^= hash >> 11;
63
2.69k
  hash += hash << 15;
64
2.69k
  return hash;
65
2.69k
}
targa_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.27k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.27k
  uint32_t hash = 0;
55
2.27k
  size_t i = 0;
56
27.4M
  while (i != size) {
57
27.4M
    hash += data[i++];
58
27.4M
    hash += hash << 10;
59
27.4M
    hash ^= hash >> 6;
60
27.4M
  }
61
2.27k
  hash += hash << 3;
62
2.27k
  hash ^= hash >> 11;
63
2.27k
  hash += hash << 15;
64
2.27k
  return hash;
65
2.27k
}
bzip2_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.34k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.34k
  uint32_t hash = 0;
55
2.34k
  size_t i = 0;
56
6.81M
  while (i != size) {
57
6.80M
    hash += data[i++];
58
6.80M
    hash += hash << 10;
59
6.80M
    hash ^= hash >> 6;
60
6.80M
  }
61
2.34k
  hash += hash << 3;
62
2.34k
  hash ^= hash >> 11;
63
2.34k
  hash += hash << 15;
64
2.34k
  return hash;
65
2.34k
}
66
67
// memrandomize is like memcpy or memset but it writes pseudo-random values.
68
static void*  //
69
0
memrandomize(void* dest, uint64_t seed, size_t n) {
70
0
  unsigned short xsubi[3];  // See "man 3 nrand48".
71
0
  xsubi[0] = (seed >> 0) ^ (seed >> 48);
72
0
  xsubi[1] = (seed >> 16);
73
0
  xsubi[2] = (seed >> 32);
74
0
  for (uint8_t* ptr = (uint8_t*)dest; n--;) {
75
0
    *ptr++ = nrand48(xsubi);
76
0
  }
77
0
  return dest;
78
0
}
Unexecuted instantiation: png_fuzzer.c:memrandomize
Unexecuted instantiation: json_fuzzer.cc:memrandomize(void*, unsigned long, unsigned long)
Unexecuted instantiation: gif_fuzzer.c:memrandomize
Unexecuted instantiation: xz_fuzzer.c:memrandomize
Unexecuted instantiation: jpeg_fuzzer.c:memrandomize
Unexecuted instantiation: cbor_fuzzer.c:memrandomize
Unexecuted instantiation: bmp_fuzzer.c:memrandomize
Unexecuted instantiation: pixel_swizzler_fuzzer.c:memrandomize
Unexecuted instantiation: zlib_fuzzer.c:memrandomize
Unexecuted instantiation: targa_fuzzer.c:memrandomize
Unexecuted instantiation: bzip2_fuzzer.c:memrandomize
79
80
const char*  //
81
fuzz(wuffs_base__io_buffer* src, uint64_t hash);
82
83
static const char*  //
84
37.8k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
37.8k
  size_t s2 = size / 2;
87
37.8k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
37.8k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
37.8k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
37.8k
  const bool closed = !(1 & popcount32(hash0));
93
94
37.8k
  wuffs_base__io_buffer src =
95
37.8k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
37.8k
  const char* msg = fuzz(&src, hash);
98
37.8k
  if (msg) {
99
34.6k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
34.6k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
34.6k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
34.6k
  }
110
37.8k
  return msg;
111
37.8k
}
png_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
5.73k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
5.73k
  size_t s2 = size / 2;
87
5.73k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
5.73k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
5.73k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
5.73k
  const bool closed = !(1 & popcount32(hash0));
93
94
5.73k
  wuffs_base__io_buffer src =
95
5.73k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
5.73k
  const char* msg = fuzz(&src, hash);
98
5.73k
  if (msg) {
99
5.72k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
5.72k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
5.72k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
5.72k
  }
110
5.73k
  return msg;
111
5.73k
}
json_fuzzer.cc:llvmFuzzerTestOneInput(unsigned char const*, unsigned long)
Line
Count
Source
84
5.92k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
5.92k
  size_t s2 = size / 2;
87
5.92k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
5.92k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
5.92k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
5.92k
  const bool closed = !(1 & popcount32(hash0));
93
94
5.92k
  wuffs_base__io_buffer src =
95
5.92k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
5.92k
  const char* msg = fuzz(&src, hash);
98
5.92k
  if (msg) {
99
4.72k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
4.72k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
4.72k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
4.72k
  }
110
5.92k
  return msg;
111
5.92k
}
gif_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
2.17k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
2.17k
  size_t s2 = size / 2;
87
2.17k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
2.17k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
2.17k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
2.17k
  const bool closed = !(1 & popcount32(hash0));
93
94
2.17k
  wuffs_base__io_buffer src =
95
2.17k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
2.17k
  const char* msg = fuzz(&src, hash);
98
2.17k
  if (msg) {
99
2.11k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
2.11k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
2.11k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
2.11k
  }
110
2.17k
  return msg;
111
2.17k
}
xz_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
8.19k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
8.19k
  size_t s2 = size / 2;
87
8.19k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
8.19k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
8.19k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
8.19k
  const bool closed = !(1 & popcount32(hash0));
93
94
8.19k
  wuffs_base__io_buffer src =
95
8.19k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
8.19k
  const char* msg = fuzz(&src, hash);
98
8.19k
  if (msg) {
99
8.19k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
8.19k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
8.19k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
8.19k
  }
110
8.19k
  return msg;
111
8.19k
}
jpeg_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
3.76k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
3.76k
  size_t s2 = size / 2;
87
3.76k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
3.76k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
3.76k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
3.76k
  const bool closed = !(1 & popcount32(hash0));
93
94
3.76k
  wuffs_base__io_buffer src =
95
3.76k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
3.76k
  const char* msg = fuzz(&src, hash);
98
3.76k
  if (msg) {
99
3.76k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
3.76k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
3.76k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
3.76k
  }
110
3.76k
  return msg;
111
3.76k
}
cbor_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
2.10k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
2.10k
  size_t s2 = size / 2;
87
2.10k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
2.10k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
2.10k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
2.10k
  const bool closed = !(1 & popcount32(hash0));
93
94
2.10k
  wuffs_base__io_buffer src =
95
2.10k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
2.10k
  const char* msg = fuzz(&src, hash);
98
2.10k
  if (msg) {
99
1.77k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.77k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
1.77k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.77k
  }
110
2.10k
  return msg;
111
2.10k
}
bmp_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
3.10k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
3.10k
  size_t s2 = size / 2;
87
3.10k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
3.10k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
3.10k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
3.10k
  const bool closed = !(1 & popcount32(hash0));
93
94
3.10k
  wuffs_base__io_buffer src =
95
3.10k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
3.10k
  const char* msg = fuzz(&src, hash);
98
3.10k
  if (msg) {
99
2.98k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
2.98k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
2.98k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
2.98k
  }
110
3.10k
  return msg;
111
3.10k
}
pixel_swizzler_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
3.19k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
3.19k
  size_t s2 = size / 2;
87
3.19k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
3.19k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
3.19k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
3.19k
  const bool closed = !(1 & popcount32(hash0));
93
94
3.19k
  wuffs_base__io_buffer src =
95
3.19k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
3.19k
  const char* msg = fuzz(&src, hash);
98
3.19k
  if (msg) {
99
1.82k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.82k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
1.82k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.82k
  }
110
3.19k
  return msg;
111
3.19k
}
zlib_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.34k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
1.34k
  size_t s2 = size / 2;
87
1.34k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.34k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.34k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.34k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.34k
  wuffs_base__io_buffer src =
95
1.34k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.34k
  const char* msg = fuzz(&src, hash);
98
1.34k
  if (msg) {
99
1.31k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.31k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
1.31k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.31k
  }
110
1.34k
  return msg;
111
1.34k
}
targa_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.13k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
1.13k
  size_t s2 = size / 2;
87
1.13k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.13k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.13k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.13k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.13k
  wuffs_base__io_buffer src =
95
1.13k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.13k
  const char* msg = fuzz(&src, hash);
98
1.13k
  if (msg) {
99
1.09k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.09k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
1.09k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.09k
  }
110
1.13k
  return msg;
111
1.13k
}
bzip2_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.17k
llvmFuzzerTestOneInput(const uint8_t* data, size_t size) {
85
  // Make a 64-bit hash out of two 32-bit hashes, each on half of the data.
86
1.17k
  size_t s2 = size / 2;
87
1.17k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.17k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.17k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.17k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.17k
  wuffs_base__io_buffer src =
95
1.17k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.17k
  const char* msg = fuzz(&src, hash);
98
1.17k
  if (msg) {
99
1.16k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.16k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
1.16k
    } else if (strstr(msg, "internal error:")) {
106
0
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.16k
  }
110
1.17k
  return msg;
111
1.17k
}
112
113
#ifdef __cplusplus
114
extern "C" {
115
#endif
116
117
int  //
118
37.8k
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
119
37.8k
  llvmFuzzerTestOneInput(data, size);
120
37.8k
  return 0;
121
37.8k
}
122
123
#ifdef __cplusplus
124
}  // extern "C"
125
#endif
126
127
static wuffs_base__io_buffer  //
128
3.18M
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
3.18M
  uint64_t n = b.meta.wi - b.meta.ri;
130
3.18M
  bool closed = b.meta.closed;
131
3.18M
  if (n > limit) {
132
479k
    n = limit;
133
479k
    closed = false;
134
479k
  }
135
136
3.18M
  wuffs_base__io_buffer ret;
137
3.18M
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
3.18M
  ret.data.len = n;
139
3.18M
  ret.meta.wi = n;
140
3.18M
  ret.meta.ri = 0;
141
3.18M
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
3.18M
  ret.meta.closed = closed;
143
3.18M
  return ret;
144
3.18M
}
Unexecuted instantiation: png_fuzzer.c:make_limited_reader
json_fuzzer.cc:make_limited_reader(wuffs_base__io_buffer__struct, unsigned long)
Line
Count
Source
128
2.47M
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
2.47M
  uint64_t n = b.meta.wi - b.meta.ri;
130
2.47M
  bool closed = b.meta.closed;
131
2.47M
  if (n > limit) {
132
374k
    n = limit;
133
374k
    closed = false;
134
374k
  }
135
136
2.47M
  wuffs_base__io_buffer ret;
137
2.47M
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
2.47M
  ret.data.len = n;
139
2.47M
  ret.meta.wi = n;
140
2.47M
  ret.meta.ri = 0;
141
2.47M
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
2.47M
  ret.meta.closed = closed;
143
2.47M
  return ret;
144
2.47M
}
Unexecuted instantiation: gif_fuzzer.c:make_limited_reader
Unexecuted instantiation: xz_fuzzer.c:make_limited_reader
Unexecuted instantiation: jpeg_fuzzer.c:make_limited_reader
cbor_fuzzer.c:make_limited_reader
Line
Count
Source
128
706k
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
706k
  uint64_t n = b.meta.wi - b.meta.ri;
130
706k
  bool closed = b.meta.closed;
131
706k
  if (n > limit) {
132
104k
    n = limit;
133
104k
    closed = false;
134
104k
  }
135
136
706k
  wuffs_base__io_buffer ret;
137
706k
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
706k
  ret.data.len = n;
139
706k
  ret.meta.wi = n;
140
706k
  ret.meta.ri = 0;
141
706k
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
706k
  ret.meta.closed = closed;
143
706k
  return ret;
144
706k
}
Unexecuted instantiation: bmp_fuzzer.c:make_limited_reader
Unexecuted instantiation: pixel_swizzler_fuzzer.c:make_limited_reader
Unexecuted instantiation: zlib_fuzzer.c:make_limited_reader
Unexecuted instantiation: targa_fuzzer.c:make_limited_reader
Unexecuted instantiation: bzip2_fuzzer.c:make_limited_reader
145
146
#ifdef WUFFS_CONFIG__FUZZLIB_MAIN
147
148
#include <dirent.h>
149
#include <errno.h>
150
#include <fcntl.h>
151
#include <stdbool.h>
152
#include <sys/mman.h>
153
#include <sys/stat.h>
154
#include <unistd.h>
155
156
struct {
157
  int remaining_argc;
158
  char** remaining_argv;
159
160
  bool color;
161
} g_flags = {0};
162
163
const char*  //
164
parse_flags(int argc, char** argv) {
165
  int c = (argc > 0) ? 1 : 0;  // Skip argv[0], the program name.
166
  for (; c < argc; c++) {
167
    char* arg = argv[c];
168
    if (*arg++ != '-') {
169
      break;
170
    }
171
172
    // A double-dash "--foo" is equivalent to a single-dash "-foo". As special
173
    // cases, a bare "-" is not a flag (some programs may interpret it as
174
    // stdin) and a bare "--" means to stop parsing flags.
175
    if (*arg == '\x00') {
176
      break;
177
    } else if (*arg == '-') {
178
      arg++;
179
      if (*arg == '\x00') {
180
        c++;
181
        break;
182
      }
183
    }
184
185
    if (!strcmp(arg, "c") || !strcmp(arg, "color")) {
186
      g_flags.color = true;
187
      continue;
188
    }
189
190
    return "main: unrecognized flag argument";
191
  }
192
193
  g_flags.remaining_argc = argc - c;
194
  g_flags.remaining_argv = argv + c;
195
  return NULL;
196
}
197
198
static int g_num_files_processed;
199
200
static struct {
201
  char buf[PATH_MAX];
202
  size_t len;
203
} g_relative_cwd;
204
205
void  //
206
errorf(const char* msg) {
207
  if (g_flags.color) {
208
    printf("\e[31m%s\e[0m\n", msg);
209
  } else {
210
    printf("%s\n", msg);
211
  }
212
}
213
214
static int  //
215
visit(char* filename);
216
217
static int  //
218
visit_dir(int fd) {
219
  int cwd_fd = open(".", O_RDONLY, 0);
220
  if (fchdir(fd)) {
221
    errorf("failed");
222
    fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
223
    return 1;
224
  }
225
226
  DIR* d = fdopendir(fd);
227
  if (!d) {
228
    errorf("failed");
229
    fprintf(stderr, "FAIL: fdopendir: %s\n", strerror(errno));
230
    return 1;
231
  }
232
233
  printf("dir\n");
234
  while (true) {
235
    struct dirent* e = readdir(d);
236
    if (!e) {
237
      break;
238
    }
239
    if ((e->d_name[0] == '\x00') || (e->d_name[0] == '.')) {
240
      continue;
241
    }
242
    int v = visit(e->d_name);
243
    if (v) {
244
      return v;
245
    }
246
  }
247
248
  if (closedir(d)) {
249
    fprintf(stderr, "FAIL: closedir: %s\n", strerror(errno));
250
    return 1;
251
  }
252
  if (fchdir(cwd_fd)) {
253
    fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
254
    return 1;
255
  }
256
  if (close(cwd_fd)) {
257
    fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
258
    return 1;
259
  }
260
  return 0;
261
}
262
263
static int  //
264
visit_reg(int fd, off_t size) {
265
  if ((size < 0) || (0x7FFFFFFF < size)) {
266
    errorf("failed");
267
    fprintf(stderr, "FAIL: file size out of bounds");
268
    return 1;
269
  }
270
271
  void* data = NULL;
272
  if (size > 0) {
273
    data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
274
    if (data == MAP_FAILED) {
275
      errorf("failed");
276
      fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
277
      return 1;
278
    }
279
  }
280
281
  const char* msg = llvmFuzzerTestOneInput((const uint8_t*)(data), size);
282
  if (msg) {
283
    errorf(msg);
284
  } else if (g_flags.color) {
285
    printf("\e[32mok\e[0m\n");
286
  } else {
287
    printf("ok\n");
288
  }
289
290
  if ((size > 0) && munmap(data, size)) {
291
    fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
292
    return 1;
293
  }
294
  if (close(fd)) {
295
    fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
296
    return 1;
297
  }
298
  return 0;
299
}
300
301
static int  //
302
visit(char* filename) {
303
  g_num_files_processed++;
304
  if (!filename || (filename[0] == '\x00')) {
305
    fprintf(stderr, "FAIL: invalid filename\n");
306
    return 1;
307
  }
308
  int n = printf("- %s%s", g_relative_cwd.buf, filename);
309
  printf("%*s", (60 > n) ? (60 - n) : 1, "");
310
  fflush(stdout);
311
312
  struct stat z;
313
  int fd = open(filename, O_RDONLY, 0);
314
  if (fd == -1) {
315
    errorf("failed");
316
    fprintf(stderr, "FAIL: open: %s\n", strerror(errno));
317
    return 1;
318
  }
319
  if (fstat(fd, &z)) {
320
    errorf("failed");
321
    fprintf(stderr, "FAIL: fstat: %s\n", strerror(errno));
322
    return 1;
323
  }
324
325
  if (S_ISREG(z.st_mode)) {
326
    return visit_reg(fd, z.st_size);
327
  } else if (!S_ISDIR(z.st_mode)) {
328
    printf("skipped\n");
329
    return 0;
330
  }
331
332
  size_t old_len = g_relative_cwd.len;
333
  size_t filename_len = strlen(filename);
334
  size_t new_len = old_len + strlen(filename);
335
  bool slash = filename[filename_len - 1] != '/';
336
  if (slash) {
337
    new_len++;
338
  }
339
  if ((filename_len >= PATH_MAX) || (new_len >= PATH_MAX)) {
340
    errorf("failed");
341
    fprintf(stderr, "FAIL: path is too long\n");
342
    return 1;
343
  }
344
  memcpy(g_relative_cwd.buf + old_len, filename, filename_len);
345
346
  if (slash) {
347
    g_relative_cwd.buf[new_len - 1] = '/';
348
  }
349
  g_relative_cwd.buf[new_len] = '\x00';
350
  g_relative_cwd.len = new_len;
351
352
  int v = visit_dir(fd);
353
354
  g_relative_cwd.buf[old_len] = '\x00';
355
  g_relative_cwd.len = old_len;
356
  return v;
357
}
358
359
int  //
360
main(int argc, char** argv) {
361
  g_num_files_processed = 0;
362
  g_relative_cwd.len = 0;
363
364
  const char* z = parse_flags(argc, argv);
365
  if (z) {
366
    fprintf(stderr, "FAIL: %s\n", z);
367
    return 1;
368
  }
369
  for (int i = 0; i < g_flags.remaining_argc; i++) {
370
    int v = visit(g_flags.remaining_argv[i]);
371
    if (v) {
372
      return v;
373
    }
374
  }
375
376
  printf("PASS: %d files processed\n", g_num_files_processed);
377
  return 0;
378
}
379
380
#endif  // WUFFS_CONFIG__FUZZLIB_MAIN