Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
fuzz_common.h
Go to the documentation of this file.
1// SPDX-License-Identifier: 0BSD
2
4//
7//
8// Authors: Maksym Vatsyk
9// Lasse Collin
10//
12
13#include <inttypes.h>
14#include <stdlib.h>
15#include <stdio.h>
16#include "lzma.h"
17
18// Some header values can make liblzma allocate a lot of RAM
19// (up to about 4 GiB with liblzma 5.2.x). We set a limit here to
20// prevent extreme allocations when fuzzing.
21#define MEM_LIMIT (300 << 20) // 300 MiB
22
23
24static void
25fuzz_code(lzma_stream *stream, const uint8_t *inbuf, size_t inbuf_size) {
26 // Output buffer for decompressed data. This is write only; nothing
27 // cares about the actual data written here.
28 uint8_t outbuf[4096];
29
30 // Give the whole input buffer at once to liblzma.
31 // Output buffer isn't initialized as liblzma only writes to it.
32 stream->next_in = inbuf;
33 stream->avail_in = inbuf_size;
34 stream->next_out = outbuf;
35 stream->avail_out = sizeof(outbuf);
36
38 while ((ret = lzma_code(stream, LZMA_FINISH)) == LZMA_OK) {
39 if (stream->avail_out == 0) {
40 // outbuf became full. We don't care about the
41 // uncompressed data there, so we simply reuse
42 // the outbuf and overwrite the old data.
43 stream->next_out = outbuf;
44 stream->avail_out = sizeof(outbuf);
45 }
46 }
47
48 // LZMA_PROG_ERROR should never happen as long as the code calling
49 // the liblzma functions is correct. Thus LZMA_PROG_ERROR is a sign
50 // of a bug in either this function or in liblzma.
51 if (ret == LZMA_PROG_ERROR) {
52 fprintf(stderr, "lzma_code() returned LZMA_PROG_ERROR\n");
53 abort();
54 }
55}
char_type outbuf[OBUFSIZ+2048]
Definition compress42.c:635
char_type inbuf[IBUFSIZ+64]
Definition compress42.c:634
Passing data to and from liblzma.
Definition base.h:485
size_t avail_out
Definition base.h:491
size_t avail_in
Definition base.h:487
uint8_t * next_out
Definition base.h:490
const uint8_t * next_in
Definition base.h:486
lzma_ret
Return values used by several functions in liblzma.
Definition base.h:57
@ LZMA_PROG_ERROR
Programming error.
Definition base.h:218
@ LZMA_OK
Operation completed successfully.
Definition base.h:58
@ LZMA_FINISH
Finish the coding operation.
Definition base.h:328
ret
Definition zlib_interface.c:30