fuzz: migrate xdiff fuzzer to use FuzzedDataProvider
authorAugie Fackler <augie@google.com>
Mon, 11 Nov 2019 16:37:18 -0500
changeset 43614 78df32a8b6f4
parent 43613 dbc39f028c9f
child 43615 6f5c352f41b6
fuzz: migrate xdiff fuzzer to use FuzzedDataProvider Differential Revision: https://phab.mercurial-scm.org/D7369
contrib/fuzz/xdiff.cc
--- a/contrib/fuzz/xdiff.cc	Mon Nov 11 14:48:30 2019 -0500
+++ b/contrib/fuzz/xdiff.cc	Mon Nov 11 16:37:18 2019 -0500
@@ -10,7 +10,7 @@
 #include <inttypes.h>
 #include <stdlib.h>
 
-#include "fuzzutil.h"
+#include <fuzzer/FuzzedDataProvider.h>
 
 extern "C" {
 
@@ -27,17 +27,15 @@
 	if (Size > 100000) {
 		return 0;
 	}
-	auto maybe_inputs = SplitInputs(Data, Size);
-	if (!maybe_inputs) {
-		return 0;
-	}
-	auto inputs = std::move(maybe_inputs.value());
+	FuzzedDataProvider provider(Data, Size);
+	std::string left = provider.ConsumeRandomLengthString(Size);
+	std::string right = provider.ConsumeRemainingBytesAsString();
 	mmfile_t a, b;
 
-	a.ptr = inputs.left.get();
-	a.size = inputs.left_size;
-	b.ptr = inputs.right.get();
-	b.size = inputs.right_size;
+	a.ptr = (char *)left.c_str();
+	a.size = left.size();
+	b.ptr = (char *)right.c_str();
+	b.size = right.size();
 	xpparam_t xpp = {
 	    XDF_INDENT_HEURISTIC, /* flags */
 	};