Coverage Report

Created: 2025-11-06 06:43

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.33k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
8
4.33k
  FuzzedDataProvider fuzzed_data(data, size);
9
4.33k
  u_int16_t i, num_iteration, is_added = 0;
10
4.33k
  ndpi_bitmap *a, *a2, *b, *c;
11
4.33k
  size_t buf_size;
12
4.33k
  char *buf;
13
4.33k
  u_int64_t value, value_added;
14
4.33k
  ndpi_bitmap_iterator *iter;
15
16
  /* To allow memory allocation failures */
17
4.33k
  fuzz_set_alloc_callbacks_and_seed(size);
18
19
4.33k
  a = ndpi_bitmap_alloc();
20
21
4.33k
  num_iteration = fuzzed_data.ConsumeIntegral<u_int16_t>();
22
57.5M
  for (i = 0; i < num_iteration; i++) {
23
57.5M
    value = fuzzed_data.ConsumeIntegral<u_int64_t>();
24
25
57.5M
    ndpi_bitmap_set(a, value);
26
    /* Keep one random entry really added */
27
57.5M
    if (is_added == 0 && fuzzed_data.ConsumeBool()) {
28
3.81k
      value_added = value;
29
3.81k
      is_added = 1;
30
3.81k
    }
31
57.5M
  }
32
33
  /* "Random" search */
34
4.33k
  num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
35
100k
  for (i = 0; i < num_iteration; i++) {
36
95.9k
    value = fuzzed_data.ConsumeIntegral<u_int64_t>();
37
38
95.9k
    ndpi_bitmap_isset(a, value);
39
95.9k
  }
40
  /* Search of an added entry */
41
4.33k
  if (is_added) {
42
3.81k
    ndpi_bitmap_isset(a, value_added);
43
3.81k
  }
44
45
4.33k
  a2 = ndpi_bitmap_copy(a);
46
47
  /* "Random" unset */
48
4.33k
  num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
49
167k
  for (i = 0; i < num_iteration; i++) {
50
163k
    value = fuzzed_data.ConsumeIntegral<u_int64_t>();
51
52
163k
    ndpi_bitmap_unset(a, value);
53
163k
  }
54
  /* Unset of an added entry */
55
4.33k
  if (is_added) {
56
3.81k
    ndpi_bitmap_unset(a, value_added);
57
3.81k
  }
58
59
4.33k
  if(fuzzed_data.ConsumeBool())
60
1.43k
    ndpi_bitmap_optimize(a);
61
62
4.33k
  ndpi_bitmap_is_empty(a);
63
4.33k
  ndpi_bitmap_cardinality(a);
64
65
4.33k
  buf_size = ndpi_bitmap_serialize(a, &buf);
66
4.33k
  b = ndpi_bitmap_deserialize(buf, buf_size);
67
4.33k
  ndpi_bitmap_free(b);
68
4.33k
  ndpi_free(buf);
69
70
4.33k
  iter = ndpi_bitmap_iterator_alloc(a);
71
167k
  for (i = 0; i < num_iteration; i++) {
72
163k
    value = fuzzed_data.ConsumeIntegral<u_int64_t>();
73
163k
    ndpi_bitmap_iterator_next(iter, &value);
74
163k
  }
75
4.33k
  ndpi_bitmap_iterator_free(iter);
76
77
4.33k
  c = ndpi_bitmap_and_alloc(a, a2);
78
4.33k
  ndpi_bitmap_free(c);
79
80
4.33k
  c = ndpi_bitmap_or_alloc(a, a2);
81
4.33k
  ndpi_bitmap_free(c);
82
83
4.33k
  if(fuzzed_data.ConsumeBool())
84
935
    ndpi_bitmap_and(a, a2);
85
4.33k
  if(fuzzed_data.ConsumeBool())
86
850
    ndpi_bitmap_andnot(a, a2);
87
4.33k
  if(fuzzed_data.ConsumeBool())
88
1.13k
    ndpi_bitmap_or(a, a2);
89
4.33k
  if(fuzzed_data.ConsumeBool())
90
1.38k
    ndpi_bitmap_xor(a, a2);
91
92
4.33k
  ndpi_bitmap_free(a);
93
4.33k
  ndpi_bitmap_free(a2);
94
95
4.33k
  return 0;
96
4.33k
}