Patchwork D7368: fuzz: migrate bdiff fuzzer to use FuzzedDataProvider

login
register
mail settings
Submitter phabricator
Date Nov. 11, 2019, 10:02 p.m.
Message ID <differential-rev-PHID-DREV-n5dqlbiugzkwb2nq2lop-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43132/
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/D7368

AFFECTED FILES
  contrib/fuzz/bdiff.cc

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 12, 2019, 3 a.m.
This revision is now accepted and ready to land.
indygreg added a comment.
indygreg accepted this revision.


  Not much context was given in the commit message. But if this makes our automated fuzzing overlords happier, then I suppose this is fine.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7368/new/

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

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

Patch

diff --git a/contrib/fuzz/bdiff.cc b/contrib/fuzz/bdiff.cc
--- a/contrib/fuzz/bdiff.cc
+++ b/contrib/fuzz/bdiff.cc
@@ -9,22 +9,20 @@ 
 #include <memory>
 #include <stdlib.h>
 
-#include "fuzzutil.h"
+#include <fuzzer/FuzzedDataProvider.h>
 
 extern "C" {
 #include "bdiff.h"
 
 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
 {
-	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();
 
 	struct bdiff_line *a, *b;
-	int an = bdiff_splitlines(inputs.left.get(), inputs.left_size, &a);
-	int bn = bdiff_splitlines(inputs.right.get(), inputs.right_size, &b);
+	int an = bdiff_splitlines(left.c_str(), left.size(), &a);
+	int bn = bdiff_splitlines(right.c_str(), right.size(), &b);
 	struct bdiff_hunk l;
 	bdiff_diff(a, an, b, bn, &l);
 	free(a);