/src/bzip2_decompress_target.c
Line  | Count  | Source  | 
1  |  | /*  | 
2  |  | # Copyright 2018 Google Inc.  | 
3  |  | #  | 
4  |  | # Licensed under the Apache License, Version 2.0 (the "License");  | 
5  |  | # you may not use this file except in compliance with the License.  | 
6  |  | # You may obtain a copy of the License at  | 
7  |  | #  | 
8  |  | #      http://www.apache.org/licenses/LICENSE-2.0  | 
9  |  | #  | 
10  |  | # Unless required by applicable law or agreed to in writing, software  | 
11  |  | # distributed under the License is distributed on an "AS IS" BASIS,  | 
12  |  | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
13  |  | # See the License for the specific language governing permissions and  | 
14  |  | # limitations under the License.  | 
15  |  | #  | 
16  |  | ###############################################################################  | 
17  |  | */  | 
18  |  |  | 
19  |  | #include "bzlib.h"  | 
20  |  | #include <stdint.h>  | 
21  |  | #include <stdlib.h>  | 
22  |  | #include <assert.h>  | 
23  |  | #include <string.h>  | 
24  |  |  | 
25  |  | extern int BZ2_bzBuffToBuffDecompress(char* dest,  | 
26  |  |                                       unsigned int* destLen,  | 
27  |  |                                       char*         source,  | 
28  |  |                                       unsigned int  sourceLen,  | 
29  |  |                                       int           small,  | 
30  |  |                                       int           verbosity);  | 
31  |  |  | 
32  |  | int  | 
33  |  | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)  | 
34  | 2.64k  | { | 
35  | 2.64k  |     int r, small;  | 
36  | 2.64k  |     unsigned int nZ, nOut;  | 
37  |  |  | 
38  |  |     // See: https://github.com/google/bzip2-rpc/blob/master/unzcrash.c#L39  | 
39  | 2.64k  |     nOut = size*2;  | 
40  | 2.64k  |     char *outbuf = malloc(nOut);  | 
41  | 2.64k  |     small = size % 2;  | 
42  | 2.64k  |     r = BZ2_bzBuffToBuffDecompress(outbuf, &nOut, (char *)data, size,  | 
43  | 2.64k  |             small, /*verbosity=*/0);  | 
44  |  |  | 
45  | 2.64k  |     if (r != BZ_OK) { | 
46  |  | #ifdef __DEBUG__  | 
47  |  |         fprintf(stdout, "Decompression error: %d\n", r);  | 
48  |  | #endif  | 
49  | 2.63k  |     }  | 
50  | 2.64k  |     free(outbuf);  | 
51  | 2.64k  |     return 0;  | 
52  | 2.64k  | }  |