/src/xz/tests/ossfuzz/fuzz_decode_stream_mt.c
Line  | Count  | Source  | 
1  |  | // SPDX-License-Identifier: 0BSD  | 
2  |  |  | 
3  |  | ///////////////////////////////////////////////////////////////////////////////  | 
4  |  | //  | 
5  |  | /// \file       fuzz_decode_stream_mt.c  | 
6  |  | /// \brief      Fuzz test program for multithreaded .xz decoding  | 
7  |  | //  | 
8  |  | //  Author:     Lasse Collin  | 
9  |  | //  | 
10  |  | ///////////////////////////////////////////////////////////////////////////////  | 
11  |  |  | 
12  |  | #include <inttypes.h>  | 
13  |  | #include <stdlib.h>  | 
14  |  | #include <stdio.h>  | 
15  |  | #include "lzma.h"  | 
16  |  | #include "fuzz_common.h"  | 
17  |  |  | 
18  |  |  | 
19  |  | extern int  | 
20  |  | LLVMFuzzerTestOneInput(const uint8_t *inbuf, size_t inbuf_size)  | 
21  | 13.6k  | { | 
22  | 13.6k  |   lzma_stream strm = LZMA_STREAM_INIT;  | 
23  |  |  | 
24  | 13.6k  |   lzma_mt mt = { | 
25  | 13.6k  |     .flags = LZMA_CONCATENATED | LZMA_IGNORE_CHECK,  | 
26  | 13.6k  |     .threads = 2,  | 
27  | 13.6k  |     .timeout = 0,  | 
28  | 13.6k  |     .memlimit_threading = MEM_LIMIT / 2,  | 
29  | 13.6k  |     .memlimit_stop = MEM_LIMIT,  | 
30  | 13.6k  |   };  | 
31  |  |  | 
32  | 13.6k  |   lzma_ret ret = lzma_stream_decoder_mt(&strm, &mt);  | 
33  |  |  | 
34  | 13.6k  |   if (ret != LZMA_OK) { | 
35  |  |     // This should never happen unless the system has  | 
36  |  |     // no free memory or address space to allow the small  | 
37  |  |     // allocations that the initialization requires.  | 
38  | 0  |     fprintf(stderr, "lzma_stream_decoder_mt() failed (%d)\n", ret);  | 
39  | 0  |     abort();  | 
40  | 0  |   }  | 
41  |  |  | 
42  | 13.6k  |   fuzz_code(&strm, inbuf, inbuf_size);  | 
43  |  |  | 
44  | 13.6k  |   lzma_end(&strm);  | 
45  |  |  | 
46  | 13.6k  |   return 0;  | 
47  | 13.6k  | }  |