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
|
|
13 extern "C" {
|
|
14
|
|
15 int hunk_consumer(long a1, long a2, long b1, long b2, void *priv)
|
|
16 {
|
|
17 // TODO: probably also test returning -1 from this when things break?
|
|
18 return 0;
|
|
19 }
|
|
20
|
|
21 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
|
22 {
|
|
23 if (!Size) {
|
|
24 return 0;
|
|
25 }
|
|
26 // figure out a random point in [0, Size] to split our input.
|
|
27 size_t split = Data[0] / 255.0 * Size;
|
|
28
|
|
29 mmfile_t a, b;
|
|
30
|
|
31 // `a` input to diff is data[1:split]
|
|
32 a.ptr = (char *)Data + 1;
|
|
33 // which has len split-1
|
|
34 a.size = split - 1;
|
|
35 // `b` starts at the next byte after `a` ends
|
|
36 b.ptr = a.ptr + a.size;
|
|
37 b.size = Size - split;
|
|
38 xpparam_t xpp = {
|
|
39 XDF_INDENT_HEURISTIC, /* flags */
|
|
40 };
|
|
41 xdemitconf_t xecfg = {
|
|
42 XDL_EMIT_BDIFFHUNK, /* flags */
|
|
43 hunk_consumer, /* hunk_consume_func */
|
|
44 };
|
|
45 xdemitcb_t ecb = {
|
|
46 NULL, /* priv */
|
|
47 };
|
|
48 xdl_diff(&a, &b, &xpp, &xecfg, &ecb);
|
|
49 return 0; // Non-zero return values are reserved for future use.
|
|
50 }
|
|
51
|
|
52 #ifdef HG_FUZZER_INCLUDE_MAIN
|
|
53 int main(int argc, char **argv)
|
|
54 {
|
|
55 const char data[] = "asdf";
|
|
56 return LLVMFuzzerTestOneInput((const uint8_t *)data, 4);
|
|
57 }
|
|
58 #endif
|
|
59
|
|
60 } // extern "C"
|