2 * Copyright (c) Meta Platforms, Inc. and affiliates.
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 * You may select, at your option, one of the above-listed licenses.
12 * This fuzz target attempts to decompress the fuzzed data with the simple
13 * decompression function to ensure the decompressor never crashes.
16 #include "fuzz_data_producer.h"
17 #define ZSTD_STATIC_LINKING_ONLY
22 #include "fuzz_helpers.h"
25 static ZSTD_DCtx *dctx = NULL;
26 static void* rBuf = NULL;
27 static size_t bufSize = 0;
29 int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
31 size_t const neededBufSize = ZSTD_BLOCKSIZE_MAX;
32 FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
34 /* Allocate all buffers and contexts if not already allocated */
35 if (neededBufSize > bufSize) {
37 rBuf = FUZZ_malloc_rand(neededBufSize, producer);
38 bufSize = neededBufSize;
41 dctx = ZSTD_createDCtx();
44 ZSTD_decompressBegin(dctx);
45 ZSTD_decompressBlock(dctx, rBuf, neededBufSize, src, size);
47 FUZZ_dataProducer_free(producer);
49 #ifndef STATEFUL_FUZZING
50 ZSTD_freeDCtx(dctx); dctx = NULL;