annotate contrib/fuzz/xdiff.cc @ 42240:39b63f9d7464

localrepo: don't use defaults arguments that will never be overridden The commithook() callback will be called when the lock is released. lock.release() calls the callback without arguments, so it was quite confusing to me that this function declared extra arguments. We can just close on the variables in the outer scope instead. Differential Revision: https://phab.mercurial-scm.org/D6336
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 03 May 2019 08:37:10 -0700
parents 2e60a77b7058
children 78df32a8b6f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36679
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
1 /*
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
2 * xdiff.cc - fuzzer harness for thirdparty/xdiff
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
3 *
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
4 * Copyright 2018, Google Inc.
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
5 *
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
6 * This software may be used and distributed according to the terms of
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
7 * the GNU General Public License, incorporated herein by reference.
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
8 */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
9 #include "thirdparty/xdiff/xdiff.h"
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
10 #include <inttypes.h>
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
11 #include <stdlib.h>
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
12
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
13 #include "fuzzutil.h"
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
14
36679
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
15 extern "C" {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
16
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
17 int hunk_consumer(long a1, long a2, long b1, long b2, void *priv)
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
18 {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
19 // TODO: probably also test returning -1 from this when things break?
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
20 return 0;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
21 }
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
22
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
23 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
24 {
41139
2e60a77b7058 xdiff: don't attempt to use fuzzer inputs larger than 100k
Augie Fackler <augie@google.com>
parents: 38173
diff changeset
25 // Don't allow fuzzer inputs larger than 100k, since we'll just bog
2e60a77b7058 xdiff: don't attempt to use fuzzer inputs larger than 100k
Augie Fackler <augie@google.com>
parents: 38173
diff changeset
26 // down and not accomplish much.
2e60a77b7058 xdiff: don't attempt to use fuzzer inputs larger than 100k
Augie Fackler <augie@google.com>
parents: 38173
diff changeset
27 if (Size > 100000) {
2e60a77b7058 xdiff: don't attempt to use fuzzer inputs larger than 100k
Augie Fackler <augie@google.com>
parents: 38173
diff changeset
28 return 0;
2e60a77b7058 xdiff: don't attempt to use fuzzer inputs larger than 100k
Augie Fackler <augie@google.com>
parents: 38173
diff changeset
29 }
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
30 auto maybe_inputs = SplitInputs(Data, Size);
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
31 if (!maybe_inputs) {
36679
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
32 return 0;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
33 }
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
34 auto inputs = std::move(maybe_inputs.value());
36679
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
35 mmfile_t a, b;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
36
38173
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
37 a.ptr = inputs.left.get();
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
38 a.size = inputs.left_size;
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
39 b.ptr = inputs.right.get();
fa0ddd5e8fff fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents: 36765
diff changeset
40 b.size = inputs.right_size;
36679
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
41 xpparam_t xpp = {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
42 XDF_INDENT_HEURISTIC, /* flags */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
43 };
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
44 xdemitconf_t xecfg = {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
45 XDL_EMIT_BDIFFHUNK, /* flags */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
46 hunk_consumer, /* hunk_consume_func */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
47 };
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
48 xdemitcb_t ecb = {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
49 NULL, /* priv */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
50 };
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
51 xdl_diff(&a, &b, &xpp, &xecfg, &ecb);
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
52 return 0; // Non-zero return values are reserved for future use.
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
53 }
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
54
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
55 #ifdef HG_FUZZER_INCLUDE_MAIN
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
56 int main(int argc, char **argv)
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
57 {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
58 const char data[] = "asdf";
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
59 return LLVMFuzzerTestOneInput((const uint8_t *)data, 4);
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
60 }
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
61 #endif
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
62
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
63 } // extern "C"