aboutsummaryrefslogtreecommitdiff
path: root/fuzz/fuzz_alg_shoco.cpp
blob: 68d2626600452c86ffb76371c1454f41c64ba573 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdint.h>
#include "shoco.h"
#include "ndpi_api.h"
#include "fuzzer/FuzzedDataProvider.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  FuzzedDataProvider fuzzed_data(data, size);
  const char *in;
  size_t in_len, out_len;
  char out[8192], orig[8192];
  int higher_level_api;

  /* No memory allocations involved */

  higher_level_api = fuzzed_data.ConsumeBool();

  std::string s = fuzzed_data.ConsumeRemainingBytesAsString().c_str();
  in = s.c_str();
  in_len = strlen(in);

  if(!higher_level_api) {
    out_len = shoco_compress(in, in_len, out, sizeof(out));
    if(out_len <= sizeof(out)) /* No error */
      shoco_decompress(out, out_len, orig, sizeof(orig));
  } else {
    out_len = ndpi_compress_str(in, in_len, out, sizeof(out));
    if(out_len != 0) /* No error */
      ndpi_decompress_str(out, out_len, orig, sizeof(orig));
  }

  return 0;
}