Add fuzzer for libsparse

Bug: 141129284
Test: SANITIZE_TARGET="hwaddress fuzzer' make libsparse_fuzzer
Change-Id: I54e19d399f7ea29a45734f1ddc520ceec56add09
This commit is contained in:
hamzeh 2019-09-25 11:00:31 -07:00
parent a550e7f412
commit d17dc6af52
2 changed files with 28 additions and 0 deletions

View file

@ -82,3 +82,15 @@ python_binary_host {
},
},
}
cc_fuzz {
name: "sparse_fuzzer",
host_supported: false,
srcs: [
"sparse_fuzzer.cpp",
],
static_libs: [
"libsparse",
"liblog",
],
}

View file

@ -0,0 +1,16 @@
#include "include/sparse/sparse.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size < 2 * sizeof(wchar_t)) return 0;
int64_t blocksize = 4096;
struct sparse_file* file = sparse_file_new(size, blocksize);
if (!file) {
return 0;
}
unsigned int block = 1;
sparse_file_add_data(file, &data, size, block);
sparse_file_destroy(file);
return 0;
}