Coverage Report

Created: 2026-06-07 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wuffs/fuzz/c/fuzzlib/fuzzlib.c
Line
Count
Source
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
42.0k
popcount32(uint32_t x) {
28
42.0k
  static const uint8_t table[256] = {
29
42.0k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
42.0k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
42.0k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
42.0k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
42.0k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
42.0k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
42.0k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
42.0k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
42.0k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
42.0k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
42.0k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
42.0k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
42.0k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
42.0k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
42.0k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
42.0k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
42.0k
  };
46
42.0k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
42.0k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
42.0k
}
png_fuzzer.c:popcount32
Line
Count
Source
27
6.02k
popcount32(uint32_t x) {
28
6.02k
  static const uint8_t table[256] = {
29
6.02k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
6.02k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
6.02k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
6.02k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
6.02k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
6.02k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
6.02k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
6.02k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
6.02k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
6.02k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
6.02k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
6.02k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
6.02k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
6.02k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
6.02k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
6.02k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
6.02k
  };
46
6.02k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
6.02k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
6.02k
}
json_fuzzer.cc:popcount32(unsigned int)
Line
Count
Source
27
5.88k
popcount32(uint32_t x) {
28
5.88k
  static const uint8_t table[256] = {
29
5.88k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
5.88k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
5.88k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
5.88k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
5.88k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
5.88k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
5.88k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
5.88k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
5.88k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
5.88k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
5.88k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
5.88k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
5.88k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
5.88k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
5.88k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
5.88k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
5.88k
  };
46
5.88k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
5.88k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
5.88k
}
gif_fuzzer.c:popcount32
Line
Count
Source
27
2.40k
popcount32(uint32_t x) {
28
2.40k
  static const uint8_t table[256] = {
29
2.40k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
2.40k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
2.40k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
2.40k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
2.40k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
2.40k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
2.40k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
2.40k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
2.40k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
2.40k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
2.40k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
2.40k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
2.40k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
2.40k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
2.40k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
2.40k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
2.40k
  };
46
2.40k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
2.40k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
2.40k
}
xz_fuzzer.c:popcount32
Line
Count
Source
27
8.43k
popcount32(uint32_t x) {
28
8.43k
  static const uint8_t table[256] = {
29
8.43k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
8.43k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
8.43k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
8.43k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
8.43k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
8.43k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
8.43k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
8.43k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
8.43k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
8.43k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
8.43k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
8.43k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
8.43k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
8.43k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
8.43k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
8.43k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
8.43k
  };
46
8.43k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
8.43k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
8.43k
}
jpeg_fuzzer.c:popcount32
Line
Count
Source
27
3.80k
popcount32(uint32_t x) {
28
3.80k
  static const uint8_t table[256] = {
29
3.80k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
3.80k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
3.80k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
3.80k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
3.80k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
3.80k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
3.80k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
3.80k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
3.80k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
3.80k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
3.80k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
3.80k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
3.80k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
3.80k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
3.80k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
3.80k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
3.80k
  };
46
3.80k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
3.80k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
3.80k
}
cbor_fuzzer.c:popcount32
Line
Count
Source
27
2.29k
popcount32(uint32_t x) {
28
2.29k
  static const uint8_t table[256] = {
29
2.29k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
2.29k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
2.29k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
2.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
2.29k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
2.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
2.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
2.29k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
2.29k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
2.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
2.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
2.29k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
2.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
2.29k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
2.29k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
2.29k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
2.29k
  };
46
2.29k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
2.29k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
2.29k
}
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.66k
popcount32(uint32_t x) {
28
3.66k
  static const uint8_t table[256] = {
29
3.66k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
3.66k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
3.66k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
3.66k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
3.66k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
3.66k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
3.66k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
3.66k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
3.66k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
3.66k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
3.66k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
3.66k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
3.66k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
3.66k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
3.66k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
3.66k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
3.66k
  };
46
3.66k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
3.66k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
3.66k
}
zlib_fuzzer.c:popcount32
Line
Count
Source
27
1.41k
popcount32(uint32_t x) {
28
1.41k
  static const uint8_t table[256] = {
29
1.41k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.41k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.41k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.41k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.41k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.41k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.41k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.41k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.41k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.41k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.41k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.41k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.41k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.41k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.41k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.41k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.41k
  };
46
1.41k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.41k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.41k
}
targa_fuzzer.c:popcount32
Line
Count
Source
27
1.24k
popcount32(uint32_t x) {
28
1.24k
  static const uint8_t table[256] = {
29
1.24k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.24k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.24k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.24k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.24k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.24k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.24k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.24k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.24k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.24k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.24k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.24k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.24k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.24k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.24k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.24k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.24k
  };
46
1.24k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.24k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.24k
}
bzip2_fuzzer.c:popcount32
Line
Count
Source
27
1.32k
popcount32(uint32_t x) {
28
1.32k
  static const uint8_t table[256] = {
29
1.32k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.32k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.32k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.32k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.32k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.32k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.32k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.32k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.32k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.32k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.32k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.32k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.32k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.32k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.32k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.32k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.32k
  };
46
1.32k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.32k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.32k
}
webp_fuzzer.c:popcount32
Line
Count
Source
27
2.38k
popcount32(uint32_t x) {
28
2.38k
  static const uint8_t table[256] = {
29
2.38k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
2.38k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
2.38k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
2.38k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
2.38k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
2.38k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
2.38k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
2.38k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
2.38k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
2.38k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
2.38k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
2.38k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
2.38k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
2.38k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
2.38k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
2.38k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
2.38k
  };
46
2.38k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
2.38k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
2.38k
}
49
50
// jenkins_hash_u32 implements
51
// https://en.wikipedia.org/wiki/Jenkins_hash_function
52
static uint32_t  //
53
84.0k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
84.0k
  uint32_t hash = 0;
55
84.0k
  size_t i = 0;
56
557M
  while (i != size) {
57
557M
    hash += data[i++];
58
557M
    hash += hash << 10;
59
557M
    hash ^= hash >> 6;
60
557M
  }
61
84.0k
  hash += hash << 3;
62
84.0k
  hash ^= hash >> 11;
63
84.0k
  hash += hash << 15;
64
84.0k
  return hash;
65
84.0k
}
png_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
12.0k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
12.0k
  uint32_t hash = 0;
55
12.0k
  size_t i = 0;
56
60.8M
  while (i != size) {
57
60.8M
    hash += data[i++];
58
60.8M
    hash += hash << 10;
59
60.8M
    hash ^= hash >> 6;
60
60.8M
  }
61
12.0k
  hash += hash << 3;
62
12.0k
  hash ^= hash >> 11;
63
12.0k
  hash += hash << 15;
64
12.0k
  return hash;
65
12.0k
}
json_fuzzer.cc:jenkins_hash_u32(unsigned char const*, unsigned long)
Line
Count
Source
53
11.7k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
11.7k
  uint32_t hash = 0;
55
11.7k
  size_t i = 0;
56
150M
  while (i != size) {
57
150M
    hash += data[i++];
58
150M
    hash += hash << 10;
59
150M
    hash ^= hash >> 6;
60
150M
  }
61
11.7k
  hash += hash << 3;
62
11.7k
  hash ^= hash >> 11;
63
11.7k
  hash += hash << 15;
64
11.7k
  return hash;
65
11.7k
}
gif_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
4.80k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
4.80k
  uint32_t hash = 0;
55
4.80k
  size_t i = 0;
56
56.8M
  while (i != size) {
57
56.8M
    hash += data[i++];
58
56.8M
    hash += hash << 10;
59
56.8M
    hash ^= hash >> 6;
60
56.8M
  }
61
4.80k
  hash += hash << 3;
62
4.80k
  hash ^= hash >> 11;
63
4.80k
  hash += hash << 15;
64
4.80k
  return hash;
65
4.80k
}
xz_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
16.8k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
16.8k
  uint32_t hash = 0;
55
16.8k
  size_t i = 0;
56
46.0M
  while (i != size) {
57
46.0M
    hash += data[i++];
58
46.0M
    hash += hash << 10;
59
46.0M
    hash ^= hash >> 6;
60
46.0M
  }
61
16.8k
  hash += hash << 3;
62
16.8k
  hash ^= hash >> 11;
63
16.8k
  hash += hash << 15;
64
16.8k
  return hash;
65
16.8k
}
jpeg_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
7.60k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
7.60k
  uint32_t hash = 0;
55
7.60k
  size_t i = 0;
56
29.6M
  while (i != size) {
57
29.6M
    hash += data[i++];
58
29.6M
    hash += hash << 10;
59
29.6M
    hash ^= hash >> 6;
60
29.6M
  }
61
7.60k
  hash += hash << 3;
62
7.60k
  hash ^= hash >> 11;
63
7.60k
  hash += hash << 15;
64
7.60k
  return hash;
65
7.60k
}
cbor_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
4.59k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
4.59k
  uint32_t hash = 0;
55
4.59k
  size_t i = 0;
56
46.5M
  while (i != size) {
57
46.5M
    hash += data[i++];
58
46.5M
    hash += hash << 10;
59
46.5M
    hash ^= hash >> 6;
60
46.5M
  }
61
4.59k
  hash += hash << 3;
62
4.59k
  hash ^= hash >> 11;
63
4.59k
  hash += hash << 15;
64
4.59k
  return hash;
65
4.59k
}
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
49.3M
  while (i != size) {
57
49.3M
    hash += data[i++];
58
49.3M
    hash += hash << 10;
59
49.3M
    hash ^= hash >> 6;
60
49.3M
  }
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
7.33k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
7.33k
  uint32_t hash = 0;
55
7.33k
  size_t i = 0;
56
25.2M
  while (i != size) {
57
25.2M
    hash += data[i++];
58
25.2M
    hash += hash << 10;
59
25.2M
    hash ^= hash >> 6;
60
25.2M
  }
61
7.33k
  hash += hash << 3;
62
7.33k
  hash ^= hash >> 11;
63
7.33k
  hash += hash << 15;
64
7.33k
  return hash;
65
7.33k
}
zlib_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.83k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.83k
  uint32_t hash = 0;
55
2.83k
  size_t i = 0;
56
18.7M
  while (i != size) {
57
18.7M
    hash += data[i++];
58
18.7M
    hash += hash << 10;
59
18.7M
    hash ^= hash >> 6;
60
18.7M
  }
61
2.83k
  hash += hash << 3;
62
2.83k
  hash ^= hash >> 11;
63
2.83k
  hash += hash << 15;
64
2.83k
  return hash;
65
2.83k
}
targa_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.48k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.48k
  uint32_t hash = 0;
55
2.48k
  size_t i = 0;
56
35.6M
  while (i != size) {
57
35.6M
    hash += data[i++];
58
35.6M
    hash += hash << 10;
59
35.6M
    hash ^= hash >> 6;
60
35.6M
  }
61
2.48k
  hash += hash << 3;
62
2.48k
  hash ^= hash >> 11;
63
2.48k
  hash += hash << 15;
64
2.48k
  return hash;
65
2.48k
}
bzip2_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.65k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.65k
  uint32_t hash = 0;
55
2.65k
  size_t i = 0;
56
7.50M
  while (i != size) {
57
7.50M
    hash += data[i++];
58
7.50M
    hash += hash << 10;
59
7.50M
    hash ^= hash >> 6;
60
7.50M
  }
61
2.65k
  hash += hash << 3;
62
2.65k
  hash ^= hash >> 11;
63
2.65k
  hash += hash << 15;
64
2.65k
  return hash;
65
2.65k
}
webp_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
4.77k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
4.77k
  uint32_t hash = 0;
55
4.77k
  size_t i = 0;
56
30.3M
  while (i != size) {
57
30.3M
    hash += data[i++];
58
30.3M
    hash += hash << 10;
59
30.3M
    hash ^= hash >> 6;
60
30.3M
  }
61
4.77k
  hash += hash << 3;
62
4.77k
  hash ^= hash >> 11;
63
4.77k
  hash += hash << 15;
64
4.77k
  return hash;
65
4.77k
}
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
Unexecuted instantiation: webp_fuzzer.c:memrandomize
79
80
const char*  //
81
fuzz(wuffs_base__io_buffer* src, uint64_t hash);
82
83
static const char*  //
84
42.0k
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
42.0k
  size_t s2 = size / 2;
87
42.0k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
42.0k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
42.0k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
42.0k
  const bool closed = !(1 & popcount32(hash0));
93
94
42.0k
  wuffs_base__io_buffer src =
95
42.0k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
42.0k
  const char* msg = fuzz(&src, hash);
98
42.0k
  if (msg) {
99
37.8k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
37.8k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
37.8k
    } 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
37.8k
  }
110
42.0k
  return msg;
111
42.0k
}
png_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
6.02k
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
6.02k
  size_t s2 = size / 2;
87
6.02k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
6.02k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
6.02k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
6.02k
  const bool closed = !(1 & popcount32(hash0));
93
94
6.02k
  wuffs_base__io_buffer src =
95
6.02k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
6.02k
  const char* msg = fuzz(&src, hash);
98
6.02k
  if (msg) {
99
6.02k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
6.02k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
6.02k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
6.02k
  }
110
6.02k
  return msg;
111
6.02k
}
json_fuzzer.cc:llvmFuzzerTestOneInput(unsigned char const*, unsigned long)
Line
Count
Source
84
5.88k
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.88k
  size_t s2 = size / 2;
87
5.88k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
5.88k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
5.88k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
5.88k
  const bool closed = !(1 & popcount32(hash0));
93
94
5.88k
  wuffs_base__io_buffer src =
95
5.88k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
5.88k
  const char* msg = fuzz(&src, hash);
98
5.88k
  if (msg) {
99
4.61k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
4.61k
    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.61k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
4.61k
  }
110
5.88k
  return msg;
111
5.88k
}
gif_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
2.40k
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.40k
  size_t s2 = size / 2;
87
2.40k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
2.40k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
2.40k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
2.40k
  const bool closed = !(1 & popcount32(hash0));
93
94
2.40k
  wuffs_base__io_buffer src =
95
2.40k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
2.40k
  const char* msg = fuzz(&src, hash);
98
2.40k
  if (msg) {
99
2.33k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
2.33k
    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.33k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
2.33k
  }
110
2.40k
  return msg;
111
2.40k
}
xz_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
8.43k
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.43k
  size_t s2 = size / 2;
87
8.43k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
8.43k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
8.43k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
8.43k
  const bool closed = !(1 & popcount32(hash0));
93
94
8.43k
  wuffs_base__io_buffer src =
95
8.43k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
8.43k
  const char* msg = fuzz(&src, hash);
98
8.43k
  if (msg) {
99
8.43k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
8.43k
    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.43k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
8.43k
  }
110
8.43k
  return msg;
111
8.43k
}
jpeg_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
3.80k
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.80k
  size_t s2 = size / 2;
87
3.80k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
3.80k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
3.80k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
3.80k
  const bool closed = !(1 & popcount32(hash0));
93
94
3.80k
  wuffs_base__io_buffer src =
95
3.80k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
3.80k
  const char* msg = fuzz(&src, hash);
98
3.80k
  if (msg) {
99
3.79k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
3.79k
    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.79k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
3.79k
  }
110
3.80k
  return msg;
111
3.80k
}
cbor_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
2.29k
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.29k
  size_t s2 = size / 2;
87
2.29k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
2.29k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
2.29k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
2.29k
  const bool closed = !(1 & popcount32(hash0));
93
94
2.29k
  wuffs_base__io_buffer src =
95
2.29k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
2.29k
  const char* msg = fuzz(&src, hash);
98
2.29k
  if (msg) {
99
1.95k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.95k
    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.95k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.95k
  }
110
2.29k
  return msg;
111
2.29k
}
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.97k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
2.97k
    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.97k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
2.97k
  }
110
3.10k
  return msg;
111
3.10k
}
pixel_swizzler_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
3.66k
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.66k
  size_t s2 = size / 2;
87
3.66k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
3.66k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
3.66k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
3.66k
  const bool closed = !(1 & popcount32(hash0));
93
94
3.66k
  wuffs_base__io_buffer src =
95
3.66k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
3.66k
  const char* msg = fuzz(&src, hash);
98
3.66k
  if (msg) {
99
2.09k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
2.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
2.09k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
2.09k
  }
110
3.66k
  return msg;
111
3.66k
}
zlib_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.41k
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.41k
  size_t s2 = size / 2;
87
1.41k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.41k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.41k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.41k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.41k
  wuffs_base__io_buffer src =
95
1.41k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.41k
  const char* msg = fuzz(&src, hash);
98
1.41k
  if (msg) {
99
1.38k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.38k
    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.38k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.38k
  }
110
1.41k
  return msg;
111
1.41k
}
targa_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.24k
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.24k
  size_t s2 = size / 2;
87
1.24k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.24k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.24k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.24k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.24k
  wuffs_base__io_buffer src =
95
1.24k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.24k
  const char* msg = fuzz(&src, hash);
98
1.24k
  if (msg) {
99
1.17k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.17k
    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.17k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.17k
  }
110
1.24k
  return msg;
111
1.24k
}
bzip2_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.32k
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.32k
  size_t s2 = size / 2;
87
1.32k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.32k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.32k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.32k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.32k
  wuffs_base__io_buffer src =
95
1.32k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.32k
  const char* msg = fuzz(&src, hash);
98
1.32k
  if (msg) {
99
1.32k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.32k
    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.32k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.32k
  }
110
1.32k
  return msg;
111
1.32k
}
webp_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
2.38k
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.38k
  size_t s2 = size / 2;
87
2.38k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
2.38k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
2.38k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
2.38k
  const bool closed = !(1 & popcount32(hash0));
93
94
2.38k
  wuffs_base__io_buffer src =
95
2.38k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
2.38k
  const char* msg = fuzz(&src, hash);
98
2.38k
  if (msg) {
99
1.72k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.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
1.72k
    } else if (strstr(msg, "internal error:")) {
106
      fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
107
0
      intentional_segfault();
108
0
    }
109
1.72k
  }
110
2.38k
  return msg;
111
2.38k
}
112
113
#ifdef __cplusplus
114
extern "C" {
115
#endif
116
117
int  //
118
42.0k
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
119
42.0k
  llvmFuzzerTestOneInput(data, size);
120
42.0k
  return 0;
121
42.0k
}
122
123
#ifdef __cplusplus
124
}  // extern "C"
125
#endif
126
127
static wuffs_base__io_buffer  //
128
3.44M
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
3.44M
  uint64_t n = b.meta.wi - b.meta.ri;
130
3.44M
  bool closed = b.meta.closed;
131
3.44M
  if (n > limit) {
132
780k
    n = limit;
133
780k
    closed = false;
134
780k
  }
135
136
3.44M
  wuffs_base__io_buffer ret;
137
3.44M
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
3.44M
  ret.data.len = n;
139
3.44M
  ret.meta.wi = n;
140
3.44M
  ret.meta.ri = 0;
141
3.44M
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
3.44M
  ret.meta.closed = closed;
143
3.44M
  return ret;
144
3.44M
}
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.70M
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
2.70M
  uint64_t n = b.meta.wi - b.meta.ri;
130
2.70M
  bool closed = b.meta.closed;
131
2.70M
  if (n > limit) {
132
647k
    n = limit;
133
647k
    closed = false;
134
647k
  }
135
136
2.70M
  wuffs_base__io_buffer ret;
137
2.70M
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
2.70M
  ret.data.len = n;
139
2.70M
  ret.meta.wi = n;
140
2.70M
  ret.meta.ri = 0;
141
2.70M
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
2.70M
  ret.meta.closed = closed;
143
2.70M
  return ret;
144
2.70M
}
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
733k
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
733k
  uint64_t n = b.meta.wi - b.meta.ri;
130
733k
  bool closed = b.meta.closed;
131
733k
  if (n > limit) {
132
133k
    n = limit;
133
133k
    closed = false;
134
133k
  }
135
136
733k
  wuffs_base__io_buffer ret;
137
733k
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
733k
  ret.data.len = n;
139
733k
  ret.meta.wi = n;
140
733k
  ret.meta.ri = 0;
141
733k
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
733k
  ret.meta.closed = closed;
143
733k
  return ret;
144
733k
}
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
Unexecuted instantiation: webp_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