1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <assert.h>
6 #include <limits.h>
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include <lz4/lz4.h>
13 
14 static const size_t kMaxBufSize = 1024 * 1024 * 500; // 500 MiB
15 
16 static char dstBuffer[kMaxBufSize] = {0};
17 
18 // fuzz_target.cc
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)19 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
20     static_assert(kMaxBufSize <= INT_MAX);
21     if (size > INT_MAX) {
22         return 0;
23     }
24     LZ4_decompress_safe(reinterpret_cast<const char*>(data), dstBuffer, static_cast<int>(size),
25                         static_cast<int>(kMaxBufSize));
26     return 0;
27 }
28