|
| 1 | +#include "ndpi_api.h" |
| 2 | + |
| 3 | +#include <stdint.h> |
| 4 | +#include <stdio.h> |
| 5 | +#include "fuzzer/FuzzedDataProvider.h" |
| 6 | + |
| 7 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 8 | + FuzzedDataProvider fuzzed_data(data, size); |
| 9 | + u_int32_t n_normal, n_attacks, n_features, i, j; |
| 10 | + double **d; |
| 11 | + void *f; |
| 12 | + |
| 13 | + /* isolationforest code doesn't handle allocation failures */ |
| 14 | + |
| 15 | + /* Data set */ |
| 16 | + n_features = fuzzed_data.ConsumeIntegralInRange<u_int32_t>(0, 8); |
| 17 | + n_normal = fuzzed_data.ConsumeIntegral<u_int8_t>(); |
| 18 | + n_attacks = fuzzed_data.ConsumeIntegral<u_int8_t>(); |
| 19 | + |
| 20 | + d = (double **)ndpi_malloc(sizeof(double *) * (n_normal + n_attacks)); |
| 21 | + |
| 22 | + for(i = 0; i < n_normal; i++) { |
| 23 | + u_int32_t l = sizeof(double) * n_features; |
| 24 | + double *row = (double *)ndpi_malloc(l); |
| 25 | + |
| 26 | + d[i] = row; |
| 27 | + for(j = 0; j < n_features; j++) |
| 28 | + row[j] = fuzzed_data.ConsumeFloatingPoint<double>(); |
| 29 | + } |
| 30 | + for(i = 0; i < n_attacks; i++) { |
| 31 | + u_int32_t l = sizeof(double) * n_features; |
| 32 | + double *row = (double *)ndpi_malloc(l); |
| 33 | + |
| 34 | + d[n_normal + i] = row; |
| 35 | + for(j = 0; j < n_features; j++) |
| 36 | + row[j] = fuzzed_data.ConsumeFloatingPoint<double>(); |
| 37 | + } |
| 38 | + |
| 39 | + f = ndpi_alloc_iforest(d, n_normal, n_features); |
| 40 | + for(i = 0; i < n_normal + n_attacks; i++) { |
| 41 | + ndpi_iforest_score(f, d[i]); |
| 42 | + } |
| 43 | + |
| 44 | + ndpi_free_iforest(f); |
| 45 | + |
| 46 | + for(i = 0; i < n_normal + n_attacks; i++) |
| 47 | + ndpi_free(d[i]); |
| 48 | + ndpi_free(d); |
| 49 | + |
| 50 | + return 0; |
| 51 | +} |
0 commit comments