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