Merge pull request #112 from randy408/fuzz
Add fuzz target for OSS-Fuzz integration
diff --git a/regress/zip_read_fuzzer.cc b/regress/zip_read_fuzzer.cc
new file mode 100644
index 0000000..9128dca
--- /dev/null
+++ b/regress/zip_read_fuzzer.cc
@@ -0,0 +1,44 @@
+#include "../lib/zip.h"
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ zip_source_t *src;
+ zip_t *za;
+ zip_error_t error;
+
+ zip_error_init(&error);
+
+ if ((src = zip_source_buffer_create(data, size, 0, &error)) == NULL)
+ {
+ zip_error_fini(&error);
+ return 0;
+ }
+
+ if ((za = zip_open_from_source(src, 0, &error)) == NULL)
+ {
+ zip_source_free(src);
+ zip_error_fini(&error);
+ return 0;
+ }
+
+ zip_error_fini(&error);
+
+ char buf[32768];
+ unsigned long n = zip_get_num_entries(za, 0);
+
+ zip_file_t *f;
+ unsigned long i;
+ for(i=0; i < n; i++)
+ {
+ f = zip_fopen_index(za, i, 0);
+ if(f==NULL) continue;
+
+ while(zip_fread(f, buf, 32768) > 0);
+
+ zip_fclose(f);
+ }
+
+ zip_close(za);
+
+ return 0;
+}
diff --git a/regress/zip_read_fuzzer.dict b/regress/zip_read_fuzzer.dict
new file mode 100644
index 0000000..b54ac52
--- /dev/null
+++ b/regress/zip_read_fuzzer.dict
@@ -0,0 +1,3 @@
+header_lfh="\x50\x4b\x03\x04"
+header_cd="\x50\x4b\x01\x02"
+header_eocd="\x50\x4b\x05\x06"