Coverage Report

Created: 2025-08-03 06:32

/src/ndpi/fuzz/fuzz_alg_hll.cpp
Line
Count
Source
1
#include "ndpi_api.h"
2
#include "fuzz_common_code.h"
3
4
#include <stdint.h>
5
#include <stdio.h>
6
#include "fuzzer/FuzzedDataProvider.h"
7
8
227
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
9
227
  FuzzedDataProvider fuzzed_data(data, size);
10
227
  u_int16_t i, num_iteration;
11
227
  struct ndpi_hll *hll;
12
227
  int rc;
13
14
  /* Just to have some data */
15
227
  if(fuzzed_data.remaining_bytes() < 2048)
16
20
    return -1;
17
18
  /* To allow memory allocation failures */
19
207
  fuzz_set_alloc_callbacks_and_seed(size);
20
21
207
  hll = (struct ndpi_hll *)ndpi_malloc(sizeof(*hll));
22
23
207
  rc = ndpi_hll_init(hll, fuzzed_data.ConsumeIntegral<u_int8_t>());
24
25
207
  if (rc == 0) {
26
183
    num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
27
7.46k
    for (i = 0; i < num_iteration; i++)
28
7.28k
      ndpi_hll_add_number(hll, fuzzed_data.ConsumeIntegral<u_int32_t>());
29
30
183
    ndpi_hll_count(hll);
31
32
183
    ndpi_hll_reset(hll);
33
34
183
    num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
35
16.6k
    for (i = 0; i < num_iteration; i++) {
36
16.4k
      std::vector<int8_t>data = fuzzed_data.ConsumeBytes<int8_t>(fuzzed_data.ConsumeIntegral<u_int8_t>());
37
16.4k
      ndpi_hll_add(hll, (char *)data.data(), data.size());
38
16.4k
    }
39
40
183
    ndpi_hll_count(hll);
41
42
183
    ndpi_hll_destroy(hll);
43
183
  }
44
45
207
  ndpi_free(hll);
46
47
207
  return 0;
48
227
}