Skip to content

Commit

Permalink
fix and improve fuzzers
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler92 authored and nmoinvaz committed Nov 14, 2024
1 parent 00d695d commit d7f5fdd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/fuzz/unzip_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (!handle)
return 1;

mz_zip_set_recover(handle, (size & 0xE0) == 0xE0);
err = mz_zip_open(handle, stream, MZ_OPEN_MODE_READ);

if (err == MZ_OK) {
Expand Down
13 changes: 12 additions & 1 deletion test/fuzz/zip_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern "C" {
/***************************************************************************/

#define MZ_FUZZ_TEST_FILENAME "foo"
#define MZ_FUZZ_TEST_PWD "test123"

/***************************************************************************/

Expand All @@ -37,6 +38,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int64_t fuzz_pos = 0;
int32_t fuzz_length = 0;
uint8_t *fuzz_buf = NULL;
const char *password = NULL;

fuzz_stream = mz_stream_mem_create();
if (!fuzz_stream)
Expand Down Expand Up @@ -77,6 +79,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
mz_stream_mem_delete(&fuzz_stream);
return 1;
}

err = mz_stream_mem_open(stream, MZ_FUZZ_TEST_FILENAME, MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_WRITE);
if (err != MZ_OK) {
mz_stream_mem_delete(&stream);
mz_stream_mem_delete(&fuzz_stream);
return 1;
}

handle = mz_zip_create();
if (!handle) {
mz_stream_mem_delete(&stream);
Expand All @@ -86,7 +96,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

err = mz_zip_open(handle, stream, MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_WRITE);
if (err == MZ_OK) {
err = mz_zip_entry_write_open(handle, &file_info, compress_level, 0, NULL);
password = file_info.flag & MZ_ZIP_FLAG_ENCRYPTED ? MZ_FUZZ_TEST_PWD : NULL;
err = mz_zip_entry_write_open(handle, &file_info, compress_level, 0, password);
if (err == MZ_OK) {
mz_stream_mem_get_buffer_at_current(fuzz_stream, (const void **)&fuzz_buf);
fuzz_pos = mz_stream_tell(fuzz_stream);
Expand Down

0 comments on commit d7f5fdd

Please sign in to comment.