Mercurial > hg
annotate contrib/fuzz/xdiff.cc @ 40978:42f59d3f714d
delta: exclude base candidate much smaller than the target
If a revision's full text is that much bigger than a base candidate full text,
we no longer consider that candidate.
This solves a pathological case we encountered on a very specify repository.
It contains a long series of changesets with a very small manifest (one file)
co-existing with others changesets using a very large manifest.
Without this filtering, we ended up considering a large number of tiny full
snapshots as a potential base. It resulted in very large delta (the size of
the full text) and mercurial spending 99% of its time compressing these
deltas.
The timing of a commit moved from about 400s to about 10s (still slow, but not
ridiculously slow).
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Mon, 17 Dec 2018 10:42:19 +0100 |
parents | fa0ddd5e8fff |
children | 2e60a77b7058 |
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 { | |
38173
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
25 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
|
26 if (!maybe_inputs) { |
36679 | 27 return 0; |
28 } | |
38173
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
29 auto inputs = std::move(maybe_inputs.value()); |
36679 | 30 mmfile_t a, b; |
31 | |
38173
fa0ddd5e8fff
fuzz: extract some common utilities and use modern C++ idioms
Augie Fackler <augie@google.com>
parents:
36765
diff
changeset
|
32 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
|
33 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
|
34 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
|
35 b.size = inputs.right_size; |
36679 | 36 xpparam_t xpp = { |
37 XDF_INDENT_HEURISTIC, /* flags */ | |
38 }; | |
39 xdemitconf_t xecfg = { | |
40 XDL_EMIT_BDIFFHUNK, /* flags */ | |
41 hunk_consumer, /* hunk_consume_func */ | |
42 }; | |
43 xdemitcb_t ecb = { | |
44 NULL, /* priv */ | |
45 }; | |
46 xdl_diff(&a, &b, &xpp, &xecfg, &ecb); | |
47 return 0; // Non-zero return values are reserved for future use. | |
48 } | |
49 | |
50 #ifdef HG_FUZZER_INCLUDE_MAIN | |
51 int main(int argc, char **argv) | |
52 { | |
53 const char data[] = "asdf"; | |
54 return LLVMFuzzerTestOneInput((const uint8_t *)data, 4); | |
55 } | |
56 #endif | |
57 | |
58 } // extern "C" |