##// END OF EJS Templates
xdiff: don't attempt to use fuzzer inputs larger than 100k...
Augie Fackler -
r41175:2e60a77b default
parent child Browse files
Show More
@@ -1,58 +1,63
1 1 /*
2 2 * xdiff.cc - fuzzer harness for thirdparty/xdiff
3 3 *
4 4 * Copyright 2018, Google Inc.
5 5 *
6 6 * This software may be used and distributed according to the terms of
7 7 * the GNU General Public License, incorporated herein by reference.
8 8 */
9 9 #include "thirdparty/xdiff/xdiff.h"
10 10 #include <inttypes.h>
11 11 #include <stdlib.h>
12 12
13 13 #include "fuzzutil.h"
14 14
15 15 extern "C" {
16 16
17 17 int hunk_consumer(long a1, long a2, long b1, long b2, void *priv)
18 18 {
19 19 // TODO: probably also test returning -1 from this when things break?
20 20 return 0;
21 21 }
22 22
23 23 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
24 24 {
25 // Don't allow fuzzer inputs larger than 100k, since we'll just bog
26 // down and not accomplish much.
27 if (Size > 100000) {
28 return 0;
29 }
25 30 auto maybe_inputs = SplitInputs(Data, Size);
26 31 if (!maybe_inputs) {
27 32 return 0;
28 33 }
29 34 auto inputs = std::move(maybe_inputs.value());
30 35 mmfile_t a, b;
31 36
32 37 a.ptr = inputs.left.get();
33 38 a.size = inputs.left_size;
34 39 b.ptr = inputs.right.get();
35 40 b.size = inputs.right_size;
36 41 xpparam_t xpp = {
37 42 XDF_INDENT_HEURISTIC, /* flags */
38 43 };
39 44 xdemitconf_t xecfg = {
40 45 XDL_EMIT_BDIFFHUNK, /* flags */
41 46 hunk_consumer, /* hunk_consume_func */
42 47 };
43 48 xdemitcb_t ecb = {
44 49 NULL, /* priv */
45 50 };
46 51 xdl_diff(&a, &b, &xpp, &xecfg, &ecb);
47 52 return 0; // Non-zero return values are reserved for future use.
48 53 }
49 54
50 55 #ifdef HG_FUZZER_INCLUDE_MAIN
51 56 int main(int argc, char **argv)
52 57 {
53 58 const char data[] = "asdf";
54 59 return LLVMFuzzerTestOneInput((const uint8_t *)data, 4);
55 60 }
56 61 #endif
57 62
58 63 } // extern "C"
General Comments 0
You need to be logged in to leave comments. Login now