summaryrefslogtreecommitdiff
path: root/libs/zip/fuzz/fuzz_stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/zip/fuzz/fuzz_stream.c')
-rw-r--r--libs/zip/fuzz/fuzz_stream.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/libs/zip/fuzz/fuzz_stream.c b/libs/zip/fuzz/fuzz_stream.c
new file mode 100644
index 0000000..6c557de
--- /dev/null
+++ b/libs/zip/fuzz/fuzz_stream.c
@@ -0,0 +1,40 @@
+#include "zip.h"
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) {
+ /* Discard inputs larger than 1MB. */
+ static const size_t MaxSize = 1024 * 1024;
+ if (size < 1 || size > MaxSize) {
+ return 0;
+ }
+
+ char *outbuf = NULL;
+ size_t outbufsize = 0;
+ {
+ struct zip_t *zip =
+ zip_stream_open(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
+ zip_entry_open(zip, "test");
+ zip_entry_write(zip, data, size);
+ zip_entry_close(zip);
+ zip_stream_copy(zip, (void **)&outbuf, &outbufsize);
+ zip_stream_close(zip);
+ }
+
+ void *inbuf = NULL;
+ size_t inbufsize = 0;
+ {
+ struct zip_t *zip = zip_stream_open(outbuf, outbufsize, 0, 'r');
+ zip_entry_open(zip, "test");
+ zip_entry_read(zip, &inbuf, &inbufsize);
+ zip_entry_close(zip);
+ zip_stream_close(zip);
+ }
+ free(inbuf);
+ free(outbuf);
+
+ assert(inbufsize == size);
+
+ return 0;
+}