• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016-2020, Facebook, Inc.
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 "fuzz_data_producer.h"
21 #include <stdint.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 extern const int kMinClevel;
28 extern const int kMaxClevel;
29 
30 void FUZZ_setRandomParameters(ZSTD_CCtx *cctx, size_t srcSize, FUZZ_dataProducer_t *producer);
31 
32 ZSTD_compressionParameters FUZZ_randomCParams(size_t srcSize, FUZZ_dataProducer_t *producer);
33 ZSTD_frameParameters FUZZ_randomFParams(FUZZ_dataProducer_t *producer);
34 ZSTD_parameters FUZZ_randomParams(size_t srcSize, FUZZ_dataProducer_t *producer);
35 
36 typedef struct {
37   void* buff;
38   size_t size;
39 } FUZZ_dict_t;
40 
41 /* Quickly train a dictionary from a source for fuzzing.
42  * NOTE: Don't use this to train production dictionaries, it is only optimized
43  * for speed, and doesn't care about dictionary quality.
44  */
45 FUZZ_dict_t FUZZ_train(void const* src, size_t srcSize, FUZZ_dataProducer_t *producer);
46 
47 #ifdef __cplusplus
48 }
49 #endif
50 
51 #endif /* ZSTD_HELPERS_H */
52