2019-09-25 20:00:31 +02:00
|
|
|
#include "include/sparse/sparse.h"
|
|
|
|
|
2021-12-31 06:09:32 +01:00
|
|
|
static volatile int count;
|
2019-09-25 20:00:31 +02:00
|
|
|
|
2021-12-31 06:09:32 +01:00
|
|
|
int WriteCallback(void* priv __attribute__((__unused__)), const void* data, size_t len) {
|
|
|
|
if (!data) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (len == 0) {
|
2019-09-25 20:00:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-31 06:09:32 +01:00
|
|
|
const char* p = (const char*)data;
|
|
|
|
// Just to make sure the data is accessible
|
|
|
|
// We only check the head and tail to save time
|
|
|
|
count += *p;
|
|
|
|
count += *(p+len-1);
|
2019-09-25 20:00:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-31 06:09:32 +01:00
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|
|
|
struct sparse_file* file = sparse_file_import_buf((char*)data, size, true, false);
|
|
|
|
if (!file) {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-04-04 10:33:55 +02:00
|
|
|
int32_t result = sparse_file_callback(file, false, false, WriteCallback, nullptr);
|
|
|
|
sparse_file_destroy(file);
|
|
|
|
return result;
|
2021-12-31 06:09:32 +01:00
|
|
|
}
|