Rizin
unix-like reverse engineering framework and cli tools
zip_read_fuzzer.cc
Go to the documentation of this file.
1 #include <zip.h>
2 
3 #ifdef __cplusplus
4 extern "C"
5 #endif
6 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
7 {
9  zip_t *za;
11  char buf[32768];
12  zip_int64_t i, n;
13  zip_file_t *f;
14 
16 
17  if ((src = zip_source_buffer_create(data, size, 0, &error)) == NULL) {
19  return 0;
20  }
21 
22  if ((za = zip_open_from_source(src, 0, &error)) == NULL) {
25  return 0;
26  }
27 
29 
30  n = zip_get_num_entries(za, 0);
31 
32  for (i = 0; i < n; i++) {
33  f = zip_fopen_index(za, i, 0);
34  if (f == NULL) {
35  continue;
36  }
37 
38  while (zip_fread(f, buf, sizeof(buf)) > 0) {
39  ;
40  }
41 
42  zip_fclose(f);
43  }
44 
45  zip_close(za);
46 
47  return 0;
48 }
lzma_index ** i
Definition: index.h:629
lzma_index * src
Definition: index.h:567
#define NULL
Definition: cris-opc.c:27
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
ZIP_EXTERN int zip_fclose(zip_file_t *_Nonnull)
Definition: zip_fclose.c:41
ZIP_EXTERN zip_t *_Nullable zip_open_from_source(zip_source_t *_Nonnull, int, zip_error_t *_Nullable)
Definition: zip_open.c:79
ZIP_EXTERN zip_source_t *_Nullable zip_source_buffer_create(const void *_Nullable, zip_uint64_t, int, zip_error_t *_Nullable)
ZIP_EXTERN void zip_error_init(zip_error_t *_Nonnull)
Definition: zip_error.c:59
ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *_Nonnull, void *_Nonnull, zip_uint64_t)
Definition: zip_fread.c:39
ZIP_EXTERN int zip_close(zip_t *_Nonnull)
Definition: zip_close.c:52
ZIP_EXTERN void zip_error_fini(zip_error_t *_Nonnull)
Definition: zip_error.c:52
ZIP_EXTERN void zip_source_free(zip_source_t *_Nullable)
ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *_Nonnull, zip_flags_t)
ZIP_EXTERN zip_file_t *_Nullable zip_fopen_index(zip_t *_Nonnull, zip_uint64_t, zip_flags_t)
int n
Definition: mipsasm.c:19
unsigned char uint8_t
Definition: sftypes.h:31
#define f(i)
Definition: sha256.c:46
Definition: zip.h:284
Definition: zipint.h:278
void error(const char *msg)
Definition: untgz.c:593
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
int64_t zip_int64_t
Definition: zipconf.h:38
zip_t * za
Definition: ziptool.c:79