summaryrefslogtreecommitdiffstats
path: root/ossfuzz/compress_fuzzer.c
blob: 39085341babc02b3543328a6eb441fe786ab6d98 (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
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "lz4.h"

#define CHECK(COND)   if (!(COND)) { abort(); }

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
  size_t const compressed_dest_size = LZ4_compressBound(size);
  char *const dest_buffer = (char *)malloc(compressed_dest_size);

  CHECK(dest_buffer != NULL);

  // Allocation succeeded, try compressing the incoming data.
  int result = LZ4_compress_default((const char*)data,
                                    dest_buffer,
                                    size,
                                    compressed_dest_size);
  CHECK(result != 0);

  free(dest_buffer);

  return 0;
}