Coverage Report

Created: 2026-04-04 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/fuzz/fuzz_ds_bitmap.cpp
Line
Count
Source
1
#include "ndpi_api.h"
2
#include "fuzz_common_code.h"
3
4
#include <stdint.h>
5
#include "fuzzer/FuzzedDataProvider.h"
6
7
4.86k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
8
4.86k
  FuzzedDataProvider fuzzed_data(data, size);
9
4.86k
  u_int16_t i, num_iteration, is_added = 0;
10
4.86k
  ndpi_bitmap *a, *a2, *b, *c;
11
4.86k
  size_t buf_size;
12
4.86k
  char *buf;
13
4.86k
  u_int64_t value, value_added;
14
4.86k
  ndpi_bitmap_iterator *iter;
15
16
  /* To allow memory allocation failures */
17
4.86k
  fuzz_set_alloc_callbacks_and_seed(size);
18
19
4.86k
  a = ndpi_bitmap_alloc();
20
21
4.86k
  num_iteration = fuzzed_data.ConsumeIntegral<u_int16_t>();
22
53.3M
  for (i = 0; i < num_iteration; i++) {
23
53.3M
    value = fuzzed_data.ConsumeIntegral<u_int64_t>();
24
25
53.3M
    ndpi_bitmap_set(a, value);
26
    /* Keep one random entry really added */
27
53.3M
    if (is_added == 0 && fuzzed_data.ConsumeBool()) {
28
4.25k
      value_added = value;
29
4.25k
      is_added = 1;
30
4.25k
    }
31
53.3M
  }
32
33
  /* "Random" search */
34
4.86k
  num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
35
74.9k
  for (i = 0; i < num_iteration; i++) {
36
70.0k
    value = fuzzed_data.ConsumeIntegral<u_int64_t>();
37
38
70.0k
    ndpi_bitmap_isset(a, value);
39
70.0k
  }
40
  /* Search of an added entry */
41
4.86k
  if (is_added) {
42
4.25k
    ndpi_bitmap_isset(a, value_added);
43
4.25k
  }
44
45
4.86k
  a2 = ndpi_bitmap_copy(a);
46
47
  /* "Random" unset */
48
4.86k
  num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
49
150k
  for (i = 0; i < num_iteration; i++) {
50
146k
    value = fuzzed_data.ConsumeIntegral<u_int64_t>();
51
52
146k
    ndpi_bitmap_unset(a, value);
53
146k
  }
54
  /* Unset of an added entry */
55
4.86k
  if (is_added) {
56
4.25k
    ndpi_bitmap_unset(a, value_added);
57
4.25k
  }
58
59
4.86k
  if(fuzzed_data.ConsumeBool())
60
1.59k
    ndpi_bitmap_optimize(a);
61
62
4.86k
  ndpi_bitmap_is_empty(a);
63
4.86k
  ndpi_bitmap_cardinality(a);
64
65
4.86k
  buf_size = ndpi_bitmap_serialize(a, &buf);
66
4.86k
  b = ndpi_bitmap_deserialize(buf, buf_size);
67
4.86k
  ndpi_bitmap_free(b);
68
4.86k
  ndpi_free(buf);
69
70
4.86k
  iter = ndpi_bitmap_iterator_alloc(a);
71
150k
  for (i = 0; i < num_iteration; i++) {
72
146k
    value = fuzzed_data.ConsumeIntegral<u_int64_t>();
73
146k
    ndpi_bitmap_iterator_next(iter, &value);
74
146k
  }
75
4.86k
  ndpi_bitmap_iterator_free(iter);
76
77
4.86k
  c = ndpi_bitmap_and_alloc(a, a2);
78
4.86k
  ndpi_bitmap_free(c);
79
80
4.86k
  c = ndpi_bitmap_or_alloc(a, a2);
81
4.86k
  ndpi_bitmap_free(c);
82
83
4.86k
  if(fuzzed_data.ConsumeBool())
84
981
    ndpi_bitmap_and(a, a2);
85
4.86k
  if(fuzzed_data.ConsumeBool())
86
883
    ndpi_bitmap_andnot(a, a2);
87
4.86k
  if(fuzzed_data.ConsumeBool())
88
1.22k
    ndpi_bitmap_or(a, a2);
89
4.86k
  if(fuzzed_data.ConsumeBool())
90
1.41k
    ndpi_bitmap_xor(a, a2);
91
92
4.86k
  ndpi_bitmap_free(a);
93
4.86k
  ndpi_bitmap_free(a2);
94
95
4.86k
  return 0;
96
4.86k
}