Coverage Report

Created: 2025-05-21 06:19

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