1 #include "include/sparse/sparse.h"
2
3 static volatile int count;
4
WriteCallback(void * priv,const void * data,size_t len)5 int WriteCallback(void* priv __attribute__((__unused__)), const void* data, size_t len) {
6 if (!data) {
7 return 0;
8 }
9 if (len == 0) {
10 return 0;
11 }
12
13 const char* p = (const char*)data;
14 // Just to make sure the data is accessible
15 // We only check the head and tail to save time
16 count += *p;
17 count += *(p+len-1);
18 return 0;
19 }
20
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
22 struct sparse_file* file = sparse_file_import_buf((char*)data, size, true, false);
23 if (!file) {
24 return 0;
25 }
26 int32_t result = sparse_file_callback(file, false, false, WriteCallback, nullptr);
27 sparse_file_destroy(file);
28 return result;
29 }
30