Patchwork D7369: fuzz: migrate xdiff fuzzer to use FuzzedDataProvider

login
register
mail settings
Submitter phabricator
Date Nov. 11, 2019, 10:02 p.m.
Message ID <differential-rev-PHID-DREV-vwcseqhvunu5efooh5lj-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43133/
State Superseded
Headers show

Comments

phabricator - Nov. 11, 2019, 10:02 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7369

AFFECTED FILES
  contrib/fuzz/xdiff.cc

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/contrib/fuzz/xdiff.cc b/contrib/fuzz/xdiff.cc
--- a/contrib/fuzz/xdiff.cc
+++ b/contrib/fuzz/xdiff.cc
@@ -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 */
 	};