Show More
@@ -0,0 +1,60 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 fm1readmarkers | |
|
19 | def maybeint(s, default): | |
|
20 | try: | |
|
21 | return int(s) | |
|
22 | except ValueError: | |
|
23 | return default | |
|
24 | try: | |
|
25 | parts = data.split('\0', 2) | |
|
26 | if len(parts) == 3: | |
|
27 | offset, stop, data = parts | |
|
28 | elif len(parts) == 2: | |
|
29 | stop, data = parts | |
|
30 | offset = 0 | |
|
31 | else: | |
|
32 | offset = stop = 0 | |
|
33 | offset, stop = maybeint(offset, 0), maybeint(stop, len(data)) | |
|
34 | fm1readmarkers(data, offset, stop) | |
|
35 | except Exception as e: | |
|
36 | pass | |
|
37 | # uncomment this print if you're editing this Python code | |
|
38 | # to debug failures. | |
|
39 | # print e | |
|
40 | )py", | |
|
41 | "fuzzer", Py_file_input); | |
|
42 | return 0; | |
|
43 | } | |
|
44 | ||
|
45 | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) | |
|
46 | { | |
|
47 | PyObject *text = | |
|
48 | PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size); | |
|
49 | PyObject *locals = PyDict_New(); | |
|
50 | PyDict_SetItemString(locals, "data", text); | |
|
51 | PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals); | |
|
52 | if (!res) { | |
|
53 | PyErr_Print(); | |
|
54 | } | |
|
55 | Py_XDECREF(res); | |
|
56 | Py_DECREF(locals); | |
|
57 | Py_DECREF(text); | |
|
58 | return 0; // Non-zero return values are reserved for future use. | |
|
59 | } | |
|
60 | } |
@@ -0,0 +1,37 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 | with zipfile.ZipFile(args.out[0], "w", zipfile.ZIP_STORED) as zf: | |
|
12 | zf.writestr( | |
|
13 | 'smallish_obsstore', | |
|
14 | ( | |
|
15 | # header: fm1readmarkers should start at offset 1, and | |
|
16 | # read until byte 597. | |
|
17 | '1\x00597\x00' | |
|
18 | # body of obsstore file | |
|
19 | '\x01\x00\x00\x00vA\xd7\x02+C\x1a<)\x01,\x00\x00\x01\x03\x03\xe6' | |
|
20 | '\x92\xde)x\x16\xd1Xph\xc7\xa7[\xe5\xe2\x1a\xab\x1e6e\xaf\xc2\xae' | |
|
21 | '\xe7\xbc\x83\xe1\x88\xa5\xda\xce>O\xbd\x04\xe9\x03\xc4o\xeb\x03' | |
|
22 | '\x01\t\x05\x04\x1fef18operationamenduserAugie Fackler <raf@duri' | |
|
23 | 'n42.com>\x00\x00\x00vA\xd7\x02-\x8aD\xaf-\x01,\x00\x00\x01\x03\x03' | |
|
24 | '\x17*\xca\x8f\x9e}i\xe0i\xbb\xdf\x9fb\x03\xd2XG?\xd3h\x98\x89\x1a' | |
|
25 | '=2\xeb\xc3\xc5<\xb3\x9e\xcc\x0e;#\xee\xc3\x10ux\x03\x01\t\x05\x04' | |
|
26 | '\x1fef18operationamenduserAugie Fackler <raf@durin42.com>\x00\x00' | |
|
27 | '\x00vA\xd7\x02Mn\xd9%\xea\x01,\x00\x00\x01\x03\x03\x98\x89\x1a=' | |
|
28 | '2\xeb\xc3\xc5<\xb3\x9e\xcc\x0e;#\xee\xc3\x10ux\xe0*\xcaT\x86Z8J' | |
|
29 | '\x85)\x97\xff7\xcc)\xc1\x7f\x19\x0c\x01\x03\x01\t\x05\x04\x1fef' | |
|
30 | '18operationamenduserAugie Fackler <raf@durin42.com>\x00\x00\x00' | |
|
31 | 'yA\xd7\x02MtA\xbfj\x01,\x00\x00\x01\x03\x03\xe0*\xcaT\x86Z8J\x85' | |
|
32 | ')\x97\xff7\xcc)\xc1\x7f\x19\x0c\x01\x00\x94\x01\xa9\n\xf80\x92\xa3' | |
|
33 | 'j\xc5X\xb1\xc9:\xd51\xb8*\xa9\x03\x01\t\x08\x04\x1fef11operatio' | |
|
34 | 'nhistedituserAugie Fackler <raf@durin42.com>\x00\x00\x00yA\xd7\x02' | |
|
35 | 'MtA\xd4\xe1\x01,\x00\x00\x01\x03\x03"\xa5\xcb\x86\xb6\xf4\xbaO\xa0' | |
|
36 | 'sH\xe7?\xcb\x9b\xc2n\xcfI\x9e\x14\xf0D\xf0!\x18DN\xcd\x97\x016\xa5' | |
|
37 | '\xef\xa06\xcb\x884\x8a\x03\x01\t\x08\x04\x1fef14operationhisted')) |
@@ -146,12 +146,23 b' dirstate_fuzzer: sanpy dirstate.cc manif' | |||
|
146 | 146 | dirstate_corpus.zip: |
|
147 | 147 | python dirstate_corpus.py $$OUT/dirstate_fuzzer_seed_corpus.zip |
|
148 | 148 | |
|
149 | fm1readmarkers_fuzzer: sanpy fm1readmarkers.cc manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o | |
|
150 | $(CXX) $(CXXFLAGS) `$$OUT/sanpy/bin/python-config --cflags` \ | |
|
151 | -Wno-register -Wno-macro-redefined \ | |
|
152 | -I../../mercurial fm1readmarkers.cc \ | |
|
153 | manifest.o charencode.o parsers.o dirs.o pathencode.o revlog.o pyutil.o \ | |
|
154 | -lFuzzingEngine `$$OUT/sanpy/bin/python-config --ldflags` \ | |
|
155 | -o $$OUT/fm1readmarkers_fuzzer | |
|
156 | ||
|
157 | fm1readmarkers_corpus.zip: | |
|
158 | python fm1readmarkers_corpus.py $$OUT/fm1readmarkers_fuzzer_seed_corpus.zip | |
|
159 | ||
|
149 | 160 | clean: |
|
150 | 161 | $(RM) *.o *_fuzzer \ |
|
151 | 162 | bdiff \ |
|
152 | 163 | mpatch \ |
|
153 | 164 | xdiff |
|
154 | 165 | |
|
155 | oss-fuzz: bdiff_fuzzer mpatch_fuzzer mpatch_corpus.zip xdiff_fuzzer manifest_fuzzer manifest_corpus.zip revlog_fuzzer revlog_corpus.zip dirstate_fuzzer dirstate_corpus.zip | |
|
166 | oss-fuzz: bdiff_fuzzer mpatch_fuzzer mpatch_corpus.zip xdiff_fuzzer manifest_fuzzer manifest_corpus.zip revlog_fuzzer revlog_corpus.zip dirstate_fuzzer dirstate_corpus.zip fm1readmarkers_fuzzer fm1readmarkers_corpus.zip | |
|
156 | 167 | |
|
157 | 168 | .PHONY: all clean oss-fuzz sanpy |
General Comments 0
You need to be logged in to leave comments.
Login now