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.
19 #include "fuzz_helpers.h"
21 #include "fuzz_data_producer.h"
23 static ZSTD_DCtx *dctx = NULL;
25 int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
27 /* Give a random portion of src data to the producer, to use for
28 parameter generation. The rest will be used for (de)compression */
29 FUZZ_dataProducer_t *producer = FUZZ_dataProducer_create(src, size);
30 size = FUZZ_dataProducer_reserveDataPrefix(producer);
33 dctx = ZSTD_createDCtx();
37 size_t const bufSize = FUZZ_dataProducer_uint32Range(producer, 0, 10 * size);
38 void *rBuf = FUZZ_malloc(bufSize);
40 ZSTD_decompressDCtx(dctx, rBuf, bufSize, src, size);
43 FUZZ_dataProducer_free(producer);
45 #ifndef STATEFUL_FUZZING
46 ZSTD_freeDCtx(dctx); dctx = NULL;