Add fuzzer for libsparse
Bug: 141129284
Test: SANITIZE_TARGET="hwaddress fuzzer' make libsparse_fuzzer
Change-Id: I54e19d399f7ea29a45734f1ddc520ceec56add09
diff --git a/libsparse/Android.bp b/libsparse/Android.bp
index 2ec4754..88146e9 100644
--- a/libsparse/Android.bp
+++ b/libsparse/Android.bp
@@ -82,3 +82,15 @@
},
},
}
+
+cc_fuzz {
+ name: "sparse_fuzzer",
+ host_supported: false,
+ srcs: [
+ "sparse_fuzzer.cpp",
+ ],
+ static_libs: [
+ "libsparse",
+ "liblog",
+ ],
+}
diff --git a/libsparse/sparse_fuzzer.cpp b/libsparse/sparse_fuzzer.cpp
new file mode 100644
index 0000000..42f331f
--- /dev/null
+++ b/libsparse/sparse_fuzzer.cpp
@@ -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;
+}