Coverage Report

Created: 2025-07-11 06:13

/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
35.8k
popcount32(uint32_t x) {
28
35.8k
  static const uint8_t table[256] = {
29
35.8k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
35.8k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
35.8k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
35.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
35.8k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
35.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
35.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
35.8k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
35.8k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
35.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
35.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
35.8k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
35.8k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
35.8k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
35.8k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
35.8k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
35.8k
  };
46
35.8k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
35.8k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
35.8k
}
png_fuzzer.c:popcount32
Line
Count
Source
27
5.56k
popcount32(uint32_t x) {
28
5.56k
  static const uint8_t table[256] = {
29
5.56k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
5.56k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
5.56k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
5.56k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
5.56k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
5.56k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
5.56k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
5.56k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
5.56k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
5.56k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
5.56k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
5.56k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
5.56k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
5.56k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
5.56k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
5.56k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
5.56k
  };
46
5.56k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
5.56k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
5.56k
}
json_fuzzer.cc:popcount32(unsigned int)
Line
Count
Source
27
5.74k
popcount32(uint32_t x) {
28
5.74k
  static const uint8_t table[256] = {
29
5.74k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
5.74k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
5.74k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
5.74k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
5.74k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
5.74k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
5.74k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
5.74k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
5.74k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
5.74k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
5.74k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
5.74k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
5.74k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
5.74k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
5.74k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
5.74k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
5.74k
  };
46
5.74k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
5.74k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
5.74k
}
gif_fuzzer.c:popcount32
Line
Count
Source
27
1.93k
popcount32(uint32_t x) {
28
1.93k
  static const uint8_t table[256] = {
29
1.93k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.93k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.93k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.93k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.93k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.93k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.93k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.93k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.93k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.93k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.93k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.93k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.93k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.93k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.93k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.93k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.93k
  };
46
1.93k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.93k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.93k
}
xz_fuzzer.c:popcount32
Line
Count
Source
27
7.68k
popcount32(uint32_t x) {
28
7.68k
  static const uint8_t table[256] = {
29
7.68k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
7.68k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
7.68k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
7.68k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
7.68k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
7.68k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
7.68k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
7.68k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
7.68k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
7.68k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
7.68k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
7.68k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
7.68k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
7.68k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
7.68k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
7.68k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
7.68k
  };
46
7.68k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
7.68k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
7.68k
}
jpeg_fuzzer.c:popcount32
Line
Count
Source
27
3.44k
popcount32(uint32_t x) {
28
3.44k
  static const uint8_t table[256] = {
29
3.44k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
3.44k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
3.44k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
3.44k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
3.44k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
3.44k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
3.44k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
3.44k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
3.44k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
3.44k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
3.44k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
3.44k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
3.44k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
3.44k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
3.44k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
3.44k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
3.44k
  };
46
3.44k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
3.44k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
3.44k
}
cbor_fuzzer.c:popcount32
Line
Count
Source
27
1.96k
popcount32(uint32_t x) {
28
1.96k
  static const uint8_t table[256] = {
29
1.96k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.96k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.96k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.96k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.96k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.96k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.96k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.96k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.96k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.96k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.96k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.96k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.96k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.96k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.96k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.96k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.96k
  };
46
1.96k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.96k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.96k
}
bmp_fuzzer.c:popcount32
Line
Count
Source
27
2.84k
popcount32(uint32_t x) {
28
2.84k
  static const uint8_t table[256] = {
29
2.84k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
2.84k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
2.84k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
2.84k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
2.84k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
2.84k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
2.84k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
2.84k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
2.84k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
2.84k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
2.84k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
2.84k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
2.84k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
2.84k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
2.84k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
2.84k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
2.84k
  };
46
2.84k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
2.84k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
2.84k
}
pixel_swizzler_fuzzer.c:popcount32
Line
Count
Source
27
3.20k
popcount32(uint32_t x) {
28
3.20k
  static const uint8_t table[256] = {
29
3.20k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
3.20k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
3.20k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
3.20k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
3.20k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
3.20k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
3.20k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
3.20k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
3.20k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
3.20k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
3.20k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
3.20k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
3.20k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
3.20k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
3.20k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
3.20k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
3.20k
  };
46
3.20k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
3.20k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
3.20k
}
zlib_fuzzer.c:popcount32
Line
Count
Source
27
1.29k
popcount32(uint32_t x) {
28
1.29k
  static const uint8_t table[256] = {
29
1.29k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.29k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.29k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.29k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.29k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.29k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.29k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.29k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.29k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.29k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.29k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.29k
  };
46
1.29k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.29k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.29k
}
targa_fuzzer.c:popcount32
Line
Count
Source
27
1.10k
popcount32(uint32_t x) {
28
1.10k
  static const uint8_t table[256] = {
29
1.10k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.10k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.10k
  };
46
1.10k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.10k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.10k
}
bzip2_fuzzer.c:popcount32
Line
Count
Source
27
1.10k
popcount32(uint32_t x) {
28
1.10k
  static const uint8_t table[256] = {
29
1.10k
      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,  //
30
1.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
31
1.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
32
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
33
1.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
34
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
35
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
36
1.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
37
1.10k
      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,  //
38
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
39
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
40
1.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
41
1.10k
      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,  //
42
1.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
43
1.10k
      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,  //
44
1.10k
      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,  //
45
1.10k
  };
46
1.10k
  return table[0xFF & (x >> 0)] + table[0xFF & (x >> 8)] +
47
1.10k
         table[0xFF & (x >> 16)] + table[0xFF & (x >> 24)];
48
1.10k
}
49
50
// jenkins_hash_u32 implements
51
// https://en.wikipedia.org/wiki/Jenkins_hash_function
52
static uint32_t  //
53
71.7k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
71.7k
  uint32_t hash = 0;
55
71.7k
  size_t i = 0;
56
465M
  while (i != size) {
57
465M
    hash += data[i++];
58
465M
    hash += hash << 10;
59
465M
    hash ^= hash >> 6;
60
465M
  }
61
71.7k
  hash += hash << 3;
62
71.7k
  hash ^= hash >> 11;
63
71.7k
  hash += hash << 15;
64
71.7k
  return hash;
65
71.7k
}
png_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
11.1k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
11.1k
  uint32_t hash = 0;
55
11.1k
  size_t i = 0;
56
55.4M
  while (i != size) {
57
55.4M
    hash += data[i++];
58
55.4M
    hash += hash << 10;
59
55.4M
    hash ^= hash >> 6;
60
55.4M
  }
61
11.1k
  hash += hash << 3;
62
11.1k
  hash ^= hash >> 11;
63
11.1k
  hash += hash << 15;
64
11.1k
  return hash;
65
11.1k
}
json_fuzzer.cc:jenkins_hash_u32(unsigned char const*, unsigned long)
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
123M
  while (i != size) {
57
123M
    hash += data[i++];
58
123M
    hash += hash << 10;
59
123M
    hash ^= hash >> 6;
60
123M
  }
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
}
gif_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
3.86k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
3.86k
  uint32_t hash = 0;
55
3.86k
  size_t i = 0;
56
48.2M
  while (i != size) {
57
48.2M
    hash += data[i++];
58
48.2M
    hash += hash << 10;
59
48.2M
    hash ^= hash >> 6;
60
48.2M
  }
61
3.86k
  hash += hash << 3;
62
3.86k
  hash ^= hash >> 11;
63
3.86k
  hash += hash << 15;
64
3.86k
  return hash;
65
3.86k
}
xz_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
15.3k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
15.3k
  uint32_t hash = 0;
55
15.3k
  size_t i = 0;
56
37.5M
  while (i != size) {
57
37.5M
    hash += data[i++];
58
37.5M
    hash += hash << 10;
59
37.5M
    hash ^= hash >> 6;
60
37.5M
  }
61
15.3k
  hash += hash << 3;
62
15.3k
  hash ^= hash >> 11;
63
15.3k
  hash += hash << 15;
64
15.3k
  return hash;
65
15.3k
}
jpeg_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
6.88k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
6.88k
  uint32_t hash = 0;
55
6.88k
  size_t i = 0;
56
27.2M
  while (i != size) {
57
27.2M
    hash += data[i++];
58
27.2M
    hash += hash << 10;
59
27.2M
    hash ^= hash >> 6;
60
27.2M
  }
61
6.88k
  hash += hash << 3;
62
6.88k
  hash ^= hash >> 11;
63
6.88k
  hash += hash << 15;
64
6.88k
  return hash;
65
6.88k
}
cbor_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
3.92k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
3.92k
  uint32_t hash = 0;
55
3.92k
  size_t i = 0;
56
38.7M
  while (i != size) {
57
38.7M
    hash += data[i++];
58
38.7M
    hash += hash << 10;
59
38.7M
    hash ^= hash >> 6;
60
38.7M
  }
61
3.92k
  hash += hash << 3;
62
3.92k
  hash ^= hash >> 11;
63
3.92k
  hash += hash << 15;
64
3.92k
  return hash;
65
3.92k
}
bmp_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
5.69k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
5.69k
  uint32_t hash = 0;
55
5.69k
  size_t i = 0;
56
50.0M
  while (i != size) {
57
50.0M
    hash += data[i++];
58
50.0M
    hash += hash << 10;
59
50.0M
    hash ^= hash >> 6;
60
50.0M
  }
61
5.69k
  hash += hash << 3;
62
5.69k
  hash ^= hash >> 11;
63
5.69k
  hash += hash << 15;
64
5.69k
  return hash;
65
5.69k
}
pixel_swizzler_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
6.40k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
6.40k
  uint32_t hash = 0;
55
6.40k
  size_t i = 0;
56
26.3M
  while (i != size) {
57
26.3M
    hash += data[i++];
58
26.3M
    hash += hash << 10;
59
26.3M
    hash ^= hash >> 6;
60
26.3M
  }
61
6.40k
  hash += hash << 3;
62
6.40k
  hash ^= hash >> 11;
63
6.40k
  hash += hash << 15;
64
6.40k
  return hash;
65
6.40k
}
zlib_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.59k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.59k
  uint32_t hash = 0;
55
2.59k
  size_t i = 0;
56
20.8M
  while (i != size) {
57
20.8M
    hash += data[i++];
58
20.8M
    hash += hash << 10;
59
20.8M
    hash ^= hash >> 6;
60
20.8M
  }
61
2.59k
  hash += hash << 3;
62
2.59k
  hash ^= hash >> 11;
63
2.59k
  hash += hash << 15;
64
2.59k
  return hash;
65
2.59k
}
targa_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.20k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.20k
  uint32_t hash = 0;
55
2.20k
  size_t i = 0;
56
30.1M
  while (i != size) {
57
30.1M
    hash += data[i++];
58
30.1M
    hash += hash << 10;
59
30.1M
    hash ^= hash >> 6;
60
30.1M
  }
61
2.20k
  hash += hash << 3;
62
2.20k
  hash ^= hash >> 11;
63
2.20k
  hash += hash << 15;
64
2.20k
  return hash;
65
2.20k
}
bzip2_fuzzer.c:jenkins_hash_u32
Line
Count
Source
53
2.20k
jenkins_hash_u32(const uint8_t* data, size_t size) {
54
2.20k
  uint32_t hash = 0;
55
2.20k
  size_t i = 0;
56
6.81M
  while (i != size) {
57
6.81M
    hash += data[i++];
58
6.81M
    hash += hash << 10;
59
6.81M
    hash ^= hash >> 6;
60
6.81M
  }
61
2.20k
  hash += hash << 3;
62
2.20k
  hash ^= hash >> 11;
63
2.20k
  hash += hash << 15;
64
2.20k
  return hash;
65
2.20k
}
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
35.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
35.8k
  size_t s2 = size / 2;
87
35.8k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
35.8k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
35.8k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
35.8k
  const bool closed = !(1 & popcount32(hash0));
93
94
35.8k
  wuffs_base__io_buffer src =
95
35.8k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
35.8k
  const char* msg = fuzz(&src, hash);
98
35.8k
  if (msg) {
99
32.7k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
32.7k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
32.7k
    } 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
32.7k
  }
110
35.8k
  return msg;
111
35.8k
}
png_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
5.56k
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.56k
  size_t s2 = size / 2;
87
5.56k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
5.56k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
5.56k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
5.56k
  const bool closed = !(1 & popcount32(hash0));
93
94
5.56k
  wuffs_base__io_buffer src =
95
5.56k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
5.56k
  const char* msg = fuzz(&src, hash);
98
5.56k
  if (msg) {
99
5.56k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
5.56k
    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.56k
    } 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.56k
  }
110
5.56k
  return msg;
111
5.56k
}
json_fuzzer.cc:llvmFuzzerTestOneInput(unsigned char const*, unsigned long)
Line
Count
Source
84
5.74k
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.74k
  size_t s2 = size / 2;
87
5.74k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
5.74k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
5.74k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
5.74k
  const bool closed = !(1 & popcount32(hash0));
93
94
5.74k
  wuffs_base__io_buffer src =
95
5.74k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
5.74k
  const char* msg = fuzz(&src, hash);
98
5.74k
  if (msg) {
99
4.58k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
4.58k
    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.58k
    } 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.58k
  }
110
5.74k
  return msg;
111
5.74k
}
gif_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.93k
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.93k
  size_t s2 = size / 2;
87
1.93k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.93k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.93k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.93k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.93k
  wuffs_base__io_buffer src =
95
1.93k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.93k
  const char* msg = fuzz(&src, hash);
98
1.93k
  if (msg) {
99
1.85k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.85k
    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.85k
    } 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.85k
  }
110
1.93k
  return msg;
111
1.93k
}
xz_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
7.68k
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
7.68k
  size_t s2 = size / 2;
87
7.68k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
7.68k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
7.68k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
7.68k
  const bool closed = !(1 & popcount32(hash0));
93
94
7.68k
  wuffs_base__io_buffer src =
95
7.68k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
7.68k
  const char* msg = fuzz(&src, hash);
98
7.68k
  if (msg) {
99
7.67k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
7.67k
    if (closed && strstr(msg, "base: short read")) {
103
0
      fprintf(stderr, "short read on a closed io_reader\n");
104
0
      intentional_segfault();
105
7.67k
    } 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
7.67k
  }
110
7.68k
  return msg;
111
7.68k
}
jpeg_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
3.44k
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.44k
  size_t s2 = size / 2;
87
3.44k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
3.44k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
3.44k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
3.44k
  const bool closed = !(1 & popcount32(hash0));
93
94
3.44k
  wuffs_base__io_buffer src =
95
3.44k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
3.44k
  const char* msg = fuzz(&src, hash);
98
3.44k
  if (msg) {
99
3.43k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
3.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
3.43k
    } 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.43k
  }
110
3.44k
  return msg;
111
3.44k
}
cbor_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.96k
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.96k
  size_t s2 = size / 2;
87
1.96k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.96k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.96k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.96k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.96k
  wuffs_base__io_buffer src =
95
1.96k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.96k
  const char* msg = fuzz(&src, hash);
98
1.96k
  if (msg) {
99
1.65k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.65k
    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.65k
    } 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.65k
  }
110
1.96k
  return msg;
111
1.96k
}
bmp_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
2.84k
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.84k
  size_t s2 = size / 2;
87
2.84k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
2.84k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
2.84k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
2.84k
  const bool closed = !(1 & popcount32(hash0));
93
94
2.84k
  wuffs_base__io_buffer src =
95
2.84k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
2.84k
  const char* msg = fuzz(&src, hash);
98
2.84k
  if (msg) {
99
2.72k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
2.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
2.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
2.72k
  }
110
2.84k
  return msg;
111
2.84k
}
pixel_swizzler_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
3.20k
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.20k
  size_t s2 = size / 2;
87
3.20k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
3.20k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
3.20k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
3.20k
  const bool closed = !(1 & popcount32(hash0));
93
94
3.20k
  wuffs_base__io_buffer src =
95
3.20k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
3.20k
  const char* msg = fuzz(&src, hash);
98
3.20k
  if (msg) {
99
1.88k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.88k
    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.88k
    } 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.88k
  }
110
3.20k
  return msg;
111
3.20k
}
zlib_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.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
1.29k
  size_t s2 = size / 2;
87
1.29k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.29k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.29k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.29k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.29k
  wuffs_base__io_buffer src =
95
1.29k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.29k
  const char* msg = fuzz(&src, hash);
98
1.29k
  if (msg) {
99
1.25k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.25k
    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.25k
    } 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.25k
  }
110
1.29k
  return msg;
111
1.29k
}
targa_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.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
1.10k
  size_t s2 = size / 2;
87
1.10k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.10k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.10k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.10k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.10k
  wuffs_base__io_buffer src =
95
1.10k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.10k
  const char* msg = fuzz(&src, hash);
98
1.10k
  if (msg) {
99
1.05k
    if (strnlen(msg, 2047) >= 2047) {
100
0
      msg = "fuzzlib: internal error: error message is too long";
101
0
    }
102
1.05k
    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.05k
    } 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.05k
  }
110
1.10k
  return msg;
111
1.10k
}
bzip2_fuzzer.c:llvmFuzzerTestOneInput
Line
Count
Source
84
1.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
1.10k
  size_t s2 = size / 2;
87
1.10k
  uint32_t hash0 = jenkins_hash_u32(data, s2);
88
1.10k
  uint32_t hash1 = jenkins_hash_u32(data + s2, size - s2);
89
1.10k
  uint64_t hash = (((uint64_t)hash0) << 32) | ((uint64_t)hash1);
90
91
  // The ! means that closed will be true for (size == 0).
92
1.10k
  const bool closed = !(1 & popcount32(hash0));
93
94
1.10k
  wuffs_base__io_buffer src =
95
1.10k
      wuffs_base__ptr_u8__reader((uint8_t*)data, size, closed);
96
97
1.10k
  const char* msg = fuzz(&src, hash);
98
1.10k
  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.10k
  return msg;
111
1.10k
}
112
113
#ifdef __cplusplus
114
extern "C" {
115
#endif
116
117
int  //
118
35.8k
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
119
35.8k
  llvmFuzzerTestOneInput(data, size);
120
35.8k
  return 0;
121
35.8k
}
122
123
#ifdef __cplusplus
124
}  // extern "C"
125
#endif
126
127
static wuffs_base__io_buffer  //
128
3.08M
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
3.08M
  uint64_t n = b.meta.wi - b.meta.ri;
130
3.08M
  bool closed = b.meta.closed;
131
3.08M
  if (n > limit) {
132
571k
    n = limit;
133
571k
    closed = false;
134
571k
  }
135
136
3.08M
  wuffs_base__io_buffer ret;
137
3.08M
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
3.08M
  ret.data.len = n;
139
3.08M
  ret.meta.wi = n;
140
3.08M
  ret.meta.ri = 0;
141
3.08M
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
3.08M
  ret.meta.closed = closed;
143
3.08M
  return ret;
144
3.08M
}
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.42M
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
2.42M
  uint64_t n = b.meta.wi - b.meta.ri;
130
2.42M
  bool closed = b.meta.closed;
131
2.42M
  if (n > limit) {
132
447k
    n = limit;
133
447k
    closed = false;
134
447k
  }
135
136
2.42M
  wuffs_base__io_buffer ret;
137
2.42M
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
2.42M
  ret.data.len = n;
139
2.42M
  ret.meta.wi = n;
140
2.42M
  ret.meta.ri = 0;
141
2.42M
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
2.42M
  ret.meta.closed = closed;
143
2.42M
  return ret;
144
2.42M
}
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
655k
make_limited_reader(wuffs_base__io_buffer b, uint64_t limit) {
129
655k
  uint64_t n = b.meta.wi - b.meta.ri;
130
655k
  bool closed = b.meta.closed;
131
655k
  if (n > limit) {
132
123k
    n = limit;
133
123k
    closed = false;
134
123k
  }
135
136
655k
  wuffs_base__io_buffer ret;
137
655k
  ret.data.ptr = b.data.ptr + b.meta.ri;
138
655k
  ret.data.len = n;
139
655k
  ret.meta.wi = n;
140
655k
  ret.meta.ri = 0;
141
655k
  ret.meta.pos = wuffs_base__u64__sat_add(b.meta.pos, b.meta.ri);
142
655k
  ret.meta.closed = closed;
143
655k
  return ret;
144
655k
}
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