Mercurial > hg
annotate contrib/fuzz/xdiff.cc @ 42042:aaececb4b066
compression: accept level management for zlib compression
We update the zlib related class to be support setting the compression level.
This changeset focus on updating the internal only. A way to configure this
level will be introduced in the next changeset.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 27 Mar 2019 19:34:10 +0100 |
parents | 2e60a77b7058 |
children | 78df32a8b6f4 |
rev | line source |
---|---|
36679 | 1 /* |
2 * xdiff.cc - fuzzer harness for thirdparty/xdiff | |
3 * | |
4 * Copyright 2018, Google Inc. | |
5 * | |
6 * This software may be used and distributed according to the terms of | |
7 * the GNU General Public License, incorporated herein by reference. | |
8 */ | |
9 #include "thirdparty/xdiff/xdiff.h" | |
10 #include <inttypes.h> | |
11 #include <stdlib.h> | |
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 | 15 extern "C" { |
16 | |
17 int hunk_consumer(long a1, long a2, long b1, long b2, void *priv) | |
18 { | |
19 // TODO: probably also test returning -1 from this when things break? | |
20 return 0; | |
21 } | |
22 | |
23 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | |
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 | 32 return 0; |
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 | 35 mmfile_t a, b; |
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 | 41 xpparam_t xpp = { |
42 XDF_INDENT_HEURISTIC, /* flags */ | |
43 }; | |
44 xdemitconf_t xecfg = { | |
45 XDL_EMIT_BDIFFHUNK, /* flags */ | |
46 hunk_consumer, /* hunk_consume_func */ | |
47 }; | |
48 xdemitcb_t ecb = { | |
49 NULL, /* priv */ | |
50 }; | |
51 xdl_diff(&a, &b, &xpp, &xecfg, &ecb); | |
52 return 0; // Non-zero return values are reserved for future use. | |
53 } | |
54 | |
55 #ifdef HG_FUZZER_INCLUDE_MAIN | |
56 int main(int argc, char **argv) | |
57 { | |
58 const char data[] = "asdf"; | |
59 return LLVMFuzzerTestOneInput((const uint8_t *)data, 4); | |
60 } | |
61 #endif | |
62 | |
63 } // extern "C" |