Coverage Report

Created: 2026-06-16 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/fuzz/fuzz_alg_isolationforest.cpp
Line
Count
Source
1
#include "ndpi_api.h"
2
3
#include <stdint.h>
4
#include <stdio.h>
5
#include "fuzzer/FuzzedDataProvider.h"
6
7
295
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
8
295
  FuzzedDataProvider fuzzed_data(data, size);
9
295
  u_int32_t n_normal, n_attacks, n_features, i, j;
10
295
  double **d;
11
295
  void *f;
12
13
  /* isolationforest code doesn't handle allocation failures */
14
15
  /* Data set */
16
295
  n_features = fuzzed_data.ConsumeIntegralInRange<u_int32_t>(0, 8);
17
295
  n_normal = fuzzed_data.ConsumeIntegral<u_int8_t>();
18
295
  n_attacks = fuzzed_data.ConsumeIntegral<u_int8_t>();
19
20
295
  d = (double **)ndpi_malloc(sizeof(double *) * (n_normal + n_attacks));
21
22
20.4k
  for(i = 0; i < n_normal; i++) {
23
20.1k
    u_int32_t l = sizeof(double) * n_features;
24
20.1k
    double *row = (double *)ndpi_malloc(l);
25
26
20.1k
    d[i] = row;
27
81.9k
    for(j = 0; j < n_features; j++)
28
61.8k
      row[j] = fuzzed_data.ConsumeFloatingPoint<double>();
29
20.1k
  }
30
24.5k
  for(i = 0; i < n_attacks; i++) {
31
24.2k
    u_int32_t l = sizeof(double) * n_features;
32
24.2k
    double *row = (double *)ndpi_malloc(l);
33
34
24.2k
    d[n_normal + i] = row;
35
108k
    for(j = 0; j < n_features; j++)
36
84.6k
      row[j] = fuzzed_data.ConsumeFloatingPoint<double>();
37
24.2k
  }
38
39
295
  f = ndpi_alloc_iforest(d, n_normal, n_features);
40
44.7k
  for(i = 0; i < n_normal + n_attacks; i++) {
41
44.4k
    ndpi_iforest_score(f, d[i]);
42
44.4k
  }
43
44
295
  ndpi_free_iforest(f);
45
46
44.7k
  for(i = 0; i < n_normal + n_attacks; i++)
47
44.4k
    ndpi_free(d[i]);
48
295
  ndpi_free(d);
49
50
295
  return 0;
51
295
}