1 // SPDX-License-Identifier: Apache-2.0
2 
3 #include <stddef.h>
4 #include <stdint.h>
5 
6 #include <ziparchive/zip_archive.h>
7 
8 // See current fuzz coverage here:
9 // https://android-coverage.googleplex.com/fuzz_targets/libziparchive_fuzzer/index.html
10 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12   ZipArchiveHandle handle = nullptr;
13   if (OpenArchiveFromMemory(data, size, "fuzz", &handle) == 0) {
14     // Iterate through all the entries.
15     void* cookie;
16     if (StartIteration(handle, &cookie) == 0) {
17       ZipEntry ze;
18       std::string name;
19       int result;
20       while ((result = Next(cookie, &ze, &name)) == 0) {
21       }
22       EndIteration(cookie);
23     }
24   }
25   CloseArchive(handle);
26   return 0;
27 }
28