| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include "mz.h" |
| 14 |
#include "mz_strm.h" |
| 15 |
#include "mz_strm_os.h" |
| 16 |
|
| 17 |
#include <stdio.h> |
| 18 |
|
| 19 |
#ifdef __cplusplus |
| 20 |
extern "C" { |
| 21 |
#endif |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
int main(int argc, char **argv) { |
| 30 |
void *stream = NULL; |
| 31 |
int64_t file_size = 0; |
| 32 |
uint8_t *buf = NULL; |
| 33 |
int32_t buf_length = 0; |
| 34 |
int32_t err = MZ_OK; |
| 35 |
int32_t read = 0; |
| 36 |
int32_t i = 0; |
| 37 |
|
| 38 |
if (argc < 1) { |
| 39 |
printf("Must specify an input file\n"); |
| 40 |
return 1; |
| 41 |
} |
| 42 |
|
| 43 |
printf("Running %" PRId32 " inputs\n", argc - 1); |
| 44 |
|
| 45 |
for (i = 1; (i < argc) && (err == MZ_OK); i++) { |
| 46 |
read = 0; |
| 47 |
|
| 48 |
stream = mz_stream_os_create(); |
| 49 |
err = mz_stream_os_open(stream, argv[i], MZ_OPEN_MODE_READ); |
| 50 |
|
| 51 |
if (err != MZ_OK) { |
| 52 |
printf("Skipping %s (%" PRId32 ")\n", argv[i], err); |
| 53 |
} else { |
| 54 |
mz_stream_os_seek(stream, 0, MZ_SEEK_END); |
| 55 |
file_size = mz_stream_os_tell(stream); |
| 56 |
if (file_size > INT32_MAX) |
| 57 |
printf("File size is too large (%" PRId64 ")\n", file_size); |
| 58 |
else |
| 59 |
buf_length = (int32_t)file_size; |
| 60 |
mz_stream_os_seek(stream, 0, MZ_SEEK_SET); |
| 61 |
|
| 62 |
buf = NULL; |
| 63 |
if (buf_length > 0) |
| 64 |
buf = malloc(buf_length); |
| 65 |
|
| 66 |
if (buf) { |
| 67 |
printf("Running %s %" PRId32 "\n", argv[i], buf_length); |
| 68 |
read = mz_stream_os_read(stream, buf, buf_length); |
| 69 |
if (read == buf_length) |
| 70 |
LLVMFuzzerTestOneInput(buf, buf_length); |
| 71 |
else |
| 72 |
err = MZ_BUF_ERROR; |
| 73 |
|
| 74 |
free(buf); |
| 75 |
} |
| 76 |
|
| 77 |
mz_stream_os_close(stream); |
| 78 |
} |
| 79 |
|
| 80 |
mz_stream_os_delete(&stream); |
| 81 |
printf("Done %s (%" PRId32 ")\n", argv[i], err); |
| 82 |
} |
| 83 |
|
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
#ifdef __cplusplus |
| 90 |
} |
| 91 |
#endif |