/src/zip/fuzz/fuzz_entry.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "zip.h" |
2 | | #include <stdint.h> |
3 | | #include <stdlib.h> |
4 | | |
5 | 3.30k | int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) { |
6 | | /* Discard inputs larger than 1MB. */ |
7 | 3.30k | static const size_t MaxSize = 1024 * 1024; |
8 | 3.30k | if (size < 1 || size > MaxSize) { |
9 | 0 | return 0; |
10 | 0 | } |
11 | | |
12 | 3.30k | void *buf = NULL; |
13 | 3.30k | size_t bufsize = 0; |
14 | 3.30k | struct zip_t *zip = zip_stream_open((const char *)data, size, 0, 'r'); |
15 | 3.30k | if (NULL == zip) { |
16 | 1.28k | goto end; |
17 | 1.28k | } |
18 | | |
19 | 2.01k | const ssize_t zip_entries_count = zip_entries_total(zip); |
20 | | |
21 | 2.01k | if (zip_entries_count <= 0) { |
22 | 44 | goto end; |
23 | 44 | } |
24 | | |
25 | 1.97k | if (0 != zip_entry_openbyindex(zip, 0)) { |
26 | 78 | goto end; |
27 | 78 | } |
28 | | |
29 | 1.89k | zip_entry_read(zip, &buf, &bufsize); |
30 | | |
31 | 3.30k | end: |
32 | 3.30k | zip_entry_close(zip); |
33 | 3.30k | if (NULL != zip) { |
34 | 2.01k | zip_close(zip); |
35 | 2.01k | } |
36 | 3.30k | free(buf); |
37 | 3.30k | return 0; |
38 | 1.89k | } |