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