Coverage Report

Created: 2025-11-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
205
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
9
205
  FuzzedDataProvider fuzzed_data(data, size);
10
205
  u_int16_t i, num_iteration;
11
205
  struct ndpi_hll *hll;
12
205
  int rc;
13
14
  /* Just to have some data */
15
205
  if(fuzzed_data.remaining_bytes() < 2048)
16
20
    return -1;
17
18
  /* To allow memory allocation failures */
19
185
  fuzz_set_alloc_callbacks_and_seed(size);
20
21
185
  hll = (struct ndpi_hll *)ndpi_malloc(sizeof(*hll));
22
23
185
  rc = ndpi_hll_init(hll, fuzzed_data.ConsumeIntegral<u_int8_t>());
24
25
185
  if (rc == 0) {
26
160
    num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
27
8.20k
    for (i = 0; i < num_iteration; i++)
28
8.04k
      ndpi_hll_add_number(hll, fuzzed_data.ConsumeIntegral<u_int32_t>());
29
30
160
    ndpi_hll_count(hll);
31
32
160
    ndpi_hll_reset(hll);
33
34
160
    num_iteration = fuzzed_data.ConsumeIntegral<u_int8_t>();
35
14.1k
    for (i = 0; i < num_iteration; i++) {
36
13.9k
      std::vector<int8_t>data = fuzzed_data.ConsumeBytes<int8_t>(fuzzed_data.ConsumeIntegral<u_int8_t>());
37
13.9k
      ndpi_hll_add(hll, (char *)data.data(), data.size());
38
13.9k
    }
39
40
160
    ndpi_hll_count(hll);
41
42
160
    ndpi_hll_destroy(hll);
43
160
  }
44
45
185
  ndpi_free(hll);
46
47
185
  return 0;
48
205
}