648db22b |
1 | /* |
2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | * All rights reserved. |
4 | * |
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. |
9 | */ |
10 | /** |
11 | * Helper functions for fuzzing. |
12 | */ |
13 | |
14 | #ifndef ZSTD_HELPERS_H |
15 | #define ZSTD_HELPERS_H |
16 | |
17 | #define ZSTD_STATIC_LINKING_ONLY |
18 | |
19 | #include "zstd.h" |
20 | #include "zstd_errors.h" |
21 | #include "fuzz_data_producer.h" |
22 | #include <stdint.h> |
23 | |
24 | #ifdef __cplusplus |
25 | extern "C" { |
26 | #endif |
27 | |
28 | extern const int kMinClevel; |
29 | extern const int kMaxClevel; |
30 | |
31 | void FUZZ_setRandomParameters(ZSTD_CCtx *cctx, size_t srcSize, FUZZ_dataProducer_t *producer); |
32 | |
33 | ZSTD_compressionParameters FUZZ_randomCParams(size_t srcSize, FUZZ_dataProducer_t *producer); |
34 | ZSTD_frameParameters FUZZ_randomFParams(FUZZ_dataProducer_t *producer); |
35 | ZSTD_parameters FUZZ_randomParams(size_t srcSize, FUZZ_dataProducer_t *producer); |
36 | |
37 | typedef struct { |
38 | void* buff; |
39 | size_t size; |
40 | } FUZZ_dict_t; |
41 | |
42 | /* Quickly train a dictionary from a source for fuzzing. |
43 | * NOTE: Don't use this to train production dictionaries, it is only optimized |
44 | * for speed, and doesn't care about dictionary quality. |
45 | */ |
46 | FUZZ_dict_t FUZZ_train(void const* src, size_t srcSize, FUZZ_dataProducer_t *producer); |
47 | |
48 | #ifdef FUZZ_THIRD_PARTY_SEQ_PROD |
49 | extern void* FUZZ_seqProdState; |
50 | #endif |
51 | |
52 | #ifdef __cplusplus |
53 | } |
54 | #endif |
55 | |
56 | #endif /* ZSTD_HELPERS_H */ |