xref: /aosp_15_r20/external/zstd/tests/fuzz/zstd_frame_info.c (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui /*
2*01826a49SYabin Cui  * Copyright (c) Meta Platforms, Inc. and affiliates.
3*01826a49SYabin Cui  * All rights reserved.
4*01826a49SYabin Cui  *
5*01826a49SYabin Cui  * This source code is licensed under both the BSD-style license (found in the
6*01826a49SYabin Cui  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*01826a49SYabin Cui  * in the COPYING file in the root directory of this source tree).
8*01826a49SYabin Cui  * You may select, at your option, one of the above-listed licenses.
9*01826a49SYabin Cui  */
10*01826a49SYabin Cui 
11*01826a49SYabin Cui /**
12*01826a49SYabin Cui  * This fuzz target fuzzes all of the helper functions that consume compressed
13*01826a49SYabin Cui  * input.
14*01826a49SYabin Cui  */
15*01826a49SYabin Cui 
16*01826a49SYabin Cui #include <stddef.h>
17*01826a49SYabin Cui #include <stdlib.h>
18*01826a49SYabin Cui #include <stdio.h>
19*01826a49SYabin Cui #include "fuzz_helpers.h"
20*01826a49SYabin Cui #include "zstd_helpers.h"
21*01826a49SYabin Cui 
LLVMFuzzerTestOneInput(const uint8_t * src,size_t size)22*01826a49SYabin Cui int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
23*01826a49SYabin Cui {
24*01826a49SYabin Cui     ZSTD_frameHeader zfh;
25*01826a49SYabin Cui     if (size == 0) {
26*01826a49SYabin Cui         src = NULL;
27*01826a49SYabin Cui    }
28*01826a49SYabin Cui     /* You can fuzz any helper functions here that are fast, and take zstd
29*01826a49SYabin Cui      * compressed data as input. E.g. don't expect the input to be a dictionary,
30*01826a49SYabin Cui      * so don't fuzz ZSTD_getDictID_fromDict().
31*01826a49SYabin Cui      */
32*01826a49SYabin Cui     ZSTD_getFrameContentSize(src, size);
33*01826a49SYabin Cui     ZSTD_getDecompressedSize(src, size);
34*01826a49SYabin Cui     ZSTD_findFrameCompressedSize(src, size);
35*01826a49SYabin Cui     ZSTD_getDictID_fromFrame(src, size);
36*01826a49SYabin Cui     ZSTD_findDecompressedSize(src, size);
37*01826a49SYabin Cui     ZSTD_decompressBound(src, size);
38*01826a49SYabin Cui     ZSTD_frameHeaderSize(src, size);
39*01826a49SYabin Cui     ZSTD_isFrame(src, size);
40*01826a49SYabin Cui     ZSTD_getFrameHeader(&zfh, src, size);
41*01826a49SYabin Cui     ZSTD_getFrameHeader_advanced(&zfh, src, size, ZSTD_f_zstd1);
42*01826a49SYabin Cui     return 0;
43*01826a49SYabin Cui }
44