contrib/fuzz/dirstate.cc
author Pulkit Goyal <7895pulkit@gmail.com>
Wed, 22 May 2019 02:59:48 +0530
changeset 42432 c767e655ffda
parent 41025 b444407f635b
child 43870 8766728dbce6
permissions -rw-r--r--
narrow: use narrow_widen wireproto command to widen in case of ellipses Few releases ago, we introduce narrow_widen wireproto command to be used to widen narrow repositories. Before this patch, that was used in non-ellipses cases only. In ellipses cases, we still do exchange.pull() which can pull more data than required. After this patch, the client will first check whether server supports doing ellipses widening using wireproto command or not by checking server's wireproto capability. If the server is upto date and support latest ellipses capability, we call the wireproto command. Otherwise we fallback to exchange.pull() like before. The compat code make sure that things works even if one of the client or server is old. The initial version of this patch does not had this compat code. It's added to help Google release things smoothly internally. I plan to drop the compat code before the upcoming major release. Due to change to wireproto command, the code looks a bit dirty, next patches will clean that up. Differential Revision: https://phab.mercurial-scm.org/D6436
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41025
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
#include <Python.h>
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
#include <assert.h>
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
#include <stdlib.h>
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
#include <unistd.h>
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
#include <string>
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
#include "pyutil.h"
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
extern "C" {
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
static PyCodeObject *code;
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
{
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
	contrib::initpy(*argv[0]);
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
	code = (PyCodeObject *)Py_CompileString(R"py(
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
from parsers import parse_dirstate
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
try:
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
    dmap = {}
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
    copymap = {}
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
    p = parse_dirstate(dmap, copymap, data)
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
except Exception as e:
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
    pass
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
    # uncomment this print if you're editing this Python code
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
    # to debug failures.
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
    # print e
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
)py",
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
	                                        "fuzzer", Py_file_input);
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
	return 0;
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
}
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
{
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
	PyObject *text =
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
	    PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size);
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
	PyObject *locals = PyDict_New();
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
	PyDict_SetItemString(locals, "data", text);
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
	PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals);
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
	if (!res) {
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
		PyErr_Print();
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
	}
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
	Py_XDECREF(res);
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
	Py_DECREF(locals);
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
	Py_DECREF(text);
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
	return 0; // Non-zero return values are reserved for future use.
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
}
b444407f635b fuzz: new fuzzer for dirstate parser
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
}