• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)33 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
34 {
35     int r, small;
36     unsigned int nZ, nOut;
37 
38     // See: https://github.com/google/bzip2-rpc/blob/master/unzcrash.c#L39
39     nOut = size*2;
40     char *outbuf = malloc(nOut);
41     small = size % 2;
42     r = BZ2_bzBuffToBuffDecompress(outbuf, &nOut, (char *)data, size,
43             small, /*verbosity=*/0);
44 
45     if (r != BZ_OK) {
46 #ifdef __DEBUG__
47         fprintf(stdout, "Decompression error: %d\n", r);
48 #endif
49     }
50     free(outbuf);
51     return 0;
52 }