1
0
mirror of https://git.tukaani.org/xz.git synced 2026-10-31 11:24:56 +00:00
xz/tests/ossfuzz/fuzz_decode_stream_mt.c

60 lines
1.3 KiB
C

// SPDX-License-Identifier: 0BSD
///////////////////////////////////////////////////////////////////////////////
//
/// \file fuzz_decode_stream_mt.c
/// \brief Fuzz test program for multithreaded .xz decoding
//
// Author: Lasse Collin
//
///////////////////////////////////////////////////////////////////////////////
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include "lzma.h"
#include "fuzz_common.h"
extern int
LLVMFuzzerTestOneInput(const uint8_t *inbuf, size_t inbuf_size)
{
lzma_stream strm = LZMA_STREAM_INIT;
prepare_stream(&strm, inbuf, inbuf_size);
lzma_mt mt = {
.flags = /*LZMA_CONCATENATED |*/ LZMA_IGNORE_CHECK,
.threads = 2,
.timeout = 0,
.memlimit_threading = MEM_LIMIT / 2,
.memlimit_stop = MEM_LIMIT,
};
lzma_ret ret;
for (int i = 0; i < 3; ++i) {
if (i == 2)
mt.flags |= LZMA_CONCATENATED;
ret = lzma_stream_decoder_mt(&strm, &mt);
if (ret == LZMA_MEM_ERROR)
continue;
if (ret != LZMA_OK) {
// This should never happen unless the system has
// no free memory or address space to allow the small
// allocations that the initialization requires.
fprintf(stderr, "lzma_stream_decoder_mt() "
"failed (%d)\n", ret);
abort();
}
fuzz_code(&strm, strm.next_in, strm.avail_in);
}
lzma_end(&strm);
return 0;
}