##// END OF EJS Templates
fuzz: new fuzzer for revlog's parse_index2 method...
Augie Fackler -
r41050:c06f0ef9 default
parent child Browse files
Show More
@@ -0,0 +1,47 b''
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 PyCodeObject *code;
13
14 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
15 {
16 contrib::initpy(*argv[0]);
17 code = (PyCodeObject *)Py_CompileString(R"py(
18 from parsers import parse_index2
19 for inline in (True, False):
20 try:
21 index, cache = parse_index2(data, inline)
22 except Exception as e:
23 pass
24 # uncomment this print if you're editing this Python code
25 # to debug failures.
26 # print e
27 )py",
28 "fuzzer", Py_file_input);
29 return 0;
30 }
31
32 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
33 {
34 PyObject *text =
35 PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size);
36 PyObject *locals = PyDict_New();
37 PyDict_SetItemString(locals, "data", text);
38 PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals);
39 if (!res) {
40 PyErr_Print();
41 }
42 Py_XDECREF(res);
43 Py_DECREF(locals);
44 Py_DECREF(text);
45 return 0; // Non-zero return values are reserved for future use.
46 }
47 }
@@ -0,0 +1,28 b''
1 from __future__ import absolute_import, print_function
2
3 import argparse
4 import os
5 import zipfile
6
7 ap = argparse.ArgumentParser()
8 ap.add_argument("out", metavar="some.zip", type=str, nargs=1)
9 args = ap.parse_args()
10
11 reporoot = os.path.normpath(os.path.join(os.path.dirname(__file__),
12 '..', '..'))
13 # typically a standalone index
14 changelog = os.path.join(reporoot, '.hg', 'store', '00changelog.i')
15 # an inline revlog with only a few revisions
16 contributing = os.path.join(
17 reporoot, '.hg', 'store', 'data', 'contrib', 'fuzz', 'mpatch.cc.i')
18
19 print(changelog, os.path.exists(changelog))
20 print(contributing, os.path.exists(contributing))
21
22 with zipfile.ZipFile(args.out[0], "w", zipfile.ZIP_STORED) as zf:
23 if os.path.exists(changelog):
24 with open(changelog) as f:
25 zf.writestr("00changelog.i", f.read())
26 if os.path.exists(contributing):
27 with open(contributing) as f:
28 zf.writestr("contributing.i", f.read())
@@ -124,12 +124,23 b' manifest_fuzzer: sanpy manifest.cc manif'
124 manifest_corpus.zip:
124 manifest_corpus.zip:
125 python manifest_corpus.py $$OUT/manifest_fuzzer_seed_corpus.zip
125 python manifest_corpus.py $$OUT/manifest_fuzzer_seed_corpus.zip
126
126
127 revlog_fuzzer: sanpy revlog.cc manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o
128 $(CXX) $(CXXFLAGS) `$$OUT/sanpy/bin/python-config --cflags` \
129 -Wno-register -Wno-macro-redefined \
130 -I../../mercurial revlog.cc \
131 manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o \
132 -lFuzzingEngine `$$OUT/sanpy/bin/python-config --ldflags` \
133 -o $$OUT/revlog_fuzzer
134
135 revlog_corpus.zip:
136 python revlog_corpus.py $$OUT/revlog_fuzzer_seed_corpus.zip
137
127 clean:
138 clean:
128 $(RM) *.o *_fuzzer \
139 $(RM) *.o *_fuzzer \
129 bdiff \
140 bdiff \
130 mpatch \
141 mpatch \
131 xdiff
142 xdiff
132
143
133 oss-fuzz: bdiff_fuzzer mpatch_fuzzer mpatch_corpus.zip xdiff_fuzzer manifest_fuzzer manifest_corpus.zip
144 oss-fuzz: bdiff_fuzzer mpatch_fuzzer mpatch_corpus.zip xdiff_fuzzer manifest_fuzzer manifest_corpus.zip revlog_fuzzer revlog_corpus.zip
134
145
135 .PHONY: all clean oss-fuzz sanpy
146 .PHONY: all clean oss-fuzz sanpy
General Comments 0
You need to be logged in to leave comments. Login now