blob: 235d15dce49da0c6a5083026fe58323b4ede5673 [file] [log] [blame]
hamzehd17dc6a2019-09-25 11:00:31 -07001#include "include/sparse/sparse.h"
2
Keith Mok0cf395c2021-12-31 05:09:32 +00003static volatile int count;
hamzehd17dc6a2019-09-25 11:00:31 -07004
Keith Mok0cf395c2021-12-31 05:09:32 +00005int WriteCallback(void* priv __attribute__((__unused__)), const void* data, size_t len) {
6 if (!data) {
7 return 0;
8 }
9 if (len == 0) {
hamzehd17dc6a2019-09-25 11:00:31 -070010 return 0;
11 }
12
Keith Mok0cf395c2021-12-31 05:09:32 +000013 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);
hamzehd17dc6a2019-09-25 11:00:31 -070018 return 0;
19}
Keith Mok0cf395c2021-12-31 05:09:32 +000020
21extern "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 return sparse_file_callback(file, false, false, WriteCallback, nullptr);
27}