equal
deleted
inserted
replaced
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 "FuzzedDataProvider.h" |
6 #include "pyutil.h" |
7 #include "pyutil.h" |
7 |
8 |
8 #include <string> |
9 #include <string> |
9 |
10 |
10 extern "C" { |
11 extern "C" { |
22 for e, _, _ in lm.iterentries(): |
23 for e, _, _ in lm.iterentries(): |
23 # also exercise __getitem__ et al |
24 # also exercise __getitem__ et al |
24 lm[e] |
25 lm[e] |
25 e in lm |
26 e in lm |
26 (e + 'nope') in lm |
27 (e + 'nope') in lm |
27 lm[b'xyzzy'] = (b'\0' * 20, 'x') |
28 lm[b'xyzzy'] = (b'\0' * nlen, 'x') |
28 # do an insert, text should change |
29 # do an insert, text should change |
29 assert lm.text() != mdata, "insert should change text and didn't: %r %r" % (lm.text(), mdata) |
30 assert lm.text() != mdata, "insert should change text and didn't: %r %r" % (lm.text(), mdata) |
30 cloned = lm.filtercopy(lambda x: x != 'xyzzy') |
31 cloned = lm.filtercopy(lambda x: x != 'xyzzy') |
31 assert cloned.text() == mdata, 'cloned text should equal mdata' |
32 assert cloned.text() == mdata, 'cloned text should equal mdata' |
32 cloned.diff(lm) |
33 cloned.diff(lm) |
49 // Don't allow fuzzer inputs larger than 100k, since we'll just bog |
50 // Don't allow fuzzer inputs larger than 100k, since we'll just bog |
50 // down and not accomplish much. |
51 // down and not accomplish much. |
51 if (Size > 100000) { |
52 if (Size > 100000) { |
52 return 0; |
53 return 0; |
53 } |
54 } |
|
55 FuzzedDataProvider provider(Data, Size); |
|
56 Py_ssize_t nodelength = provider.ConsumeBool() ? 20 : 32; |
|
57 PyObject *nlen = PyLong_FromSsize_t(nodelength); |
54 PyObject *mtext = |
58 PyObject *mtext = |
55 PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size); |
59 PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size); |
56 PyObject *locals = PyDict_New(); |
60 PyObject *locals = PyDict_New(); |
57 PyDict_SetItemString(locals, "mdata", mtext); |
61 PyDict_SetItemString(locals, "mdata", mtext); |
|
62 PyDict_SetItemString(locals, "nlen", nlen); |
58 PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals); |
63 PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals); |
59 if (!res) { |
64 if (!res) { |
60 PyErr_Print(); |
65 PyErr_Print(); |
61 } |
66 } |
62 Py_XDECREF(res); |
67 Py_XDECREF(res); |