hamzeh | d17dc6a | 2019-09-25 11:00:31 -0700 | [diff] [blame] | 1 | #include "include/sparse/sparse.h" |
| 2 | |
Keith Mok | a3b7206 | 2021-12-31 05:09:32 +0000 | [diff] [blame] | 3 | static volatile int count; |
hamzeh | d17dc6a | 2019-09-25 11:00:31 -0700 | [diff] [blame] | 4 | |
Keith Mok | a3b7206 | 2021-12-31 05:09:32 +0000 | [diff] [blame] | 5 | int WriteCallback(void* priv __attribute__((__unused__)), const void* data, size_t len) { |
| 6 | if (!data) { |
| 7 | return 0; |
| 8 | } |
| 9 | if (len == 0) { |
hamzeh | d17dc6a | 2019-09-25 11:00:31 -0700 | [diff] [blame] | 10 | return 0; |
| 11 | } |
| 12 | |
Keith Mok | a3b7206 | 2021-12-31 05:09:32 +0000 | [diff] [blame] | 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); |
hamzeh | d17dc6a | 2019-09-25 11:00:31 -0700 | [diff] [blame] | 18 | return 0; |
| 19 | } |
Keith Mok | a3b7206 | 2021-12-31 05:09:32 +0000 | [diff] [blame] | 20 | |
| 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 | } |
Devendra Singhi | 1431665 | 2022-04-04 14:03:55 +0530 | [diff] [blame] | 26 | int32_t result = sparse_file_callback(file, false, false, WriteCallback, nullptr); |
| 27 | sparse_file_destroy(file); |
| 28 | return result; |
Keith Mok | a3b7206 | 2021-12-31 05:09:32 +0000 | [diff] [blame] | 29 | } |