/src/mercurial/contrib/fuzz/revlog.cc
Line | Count | Source |
1 | | #include <Python.h> |
2 | | #include <assert.h> |
3 | | #include <stdlib.h> |
4 | | #include <unistd.h> |
5 | | |
6 | | #include <string> |
7 | | |
8 | | #include "pyutil.h" |
9 | | |
10 | | extern "C" { |
11 | | |
12 | | static PYCODETYPE *code; |
13 | | |
14 | | extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) |
15 | 16 | { |
16 | 16 | contrib::initpy(*argv[0]); |
17 | 16 | code = (PYCODETYPE *)Py_CompileString(R"py( |
18 | 16 | for inline in (True, False): |
19 | 16 | try: |
20 | 16 | index, cache = parsers.parse_index2(data, inline) |
21 | 16 | index.slicechunktodensity(list(range(len(index))), 0.5, 262144) |
22 | 16 | index.stats() |
23 | 16 | index.findsnapshots({}, 0, len(index) - 1) |
24 | 16 | 10 in index |
25 | 16 | for rev in range(len(index)): |
26 | 16 | index.reachableroots(0, [len(index)-1], [rev]) |
27 | 16 | node = index[rev][7] |
28 | 16 | partial = index.shortest(node) |
29 | 16 | index.partialmatch(node[:partial]) |
30 | 16 | index.deltachain(rev, None, True) |
31 | 16 | except Exception as e: |
32 | 16 | pass |
33 | 16 | # uncomment this print if you're editing this Python code |
34 | 16 | # to debug failures. |
35 | 16 | # print e |
36 | 16 | )py", |
37 | 16 | "fuzzer", Py_file_input); |
38 | 16 | return 0; |
39 | 16 | } |
40 | | |
41 | | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
42 | 181 | { |
43 | | // Don't allow fuzzer inputs larger than 60k, since we'll just bog |
44 | | // down and not accomplish much. |
45 | 181 | if (Size > 60000) { |
46 | 9 | return 0; |
47 | 9 | } |
48 | 172 | PyObject *text = |
49 | 172 | PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size); |
50 | 172 | PyObject *locals = PyDict_New(); |
51 | 172 | PyDict_SetItemString(locals, "data", text); |
52 | 172 | PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals); |
53 | 172 | if (!res) { |
54 | 0 | PyErr_Print(); |
55 | 0 | } |
56 | 172 | Py_XDECREF(res); |
57 | 172 | Py_DECREF(locals); |
58 | 172 | Py_DECREF(text); |
59 | 172 | return 0; // Non-zero return values are reserved for future use. |
60 | 181 | } |
61 | | } |