contrib/fuzz/xdiff.cc
author Gregory Szorc <gregory.szorc@gmail.com>
Wed, 04 Apr 2018 14:09:02 -0700
changeset 37415 c2c8962a9465
parent 36765 04d64163039a
child 38173 fa0ddd5e8fff
permissions -rw-r--r--
simplestore: use a custom store for the simple store repo Before, we used the default store, which was based on fncache and dotencode. After attempting to port tests to work with the simple store, I realized that fncache was more trouble than it is worth. This commit implements a proper store type for the simple repo - one that isn't based off fncache. This causes a number of new test failures because of tests expecting the full fncache store filename encoding. I may extend the store format in a subsequent commit to take the filename encoding parts of fncache that we can take (basically everything except hash encoding, since that isn't reversible). But for now, let's use encoded store. As part of this, we implement proper requirements support for repos created with the simple store. This should have been done from the beginning, as a requirement is needed to lock out clients that don't understand a storage format. A new hghave feature advertising the presence of fncache in repos has been added. Most tests touching the fncache are now conditional on that feature. Other tests have added the optional repo requirement to output. Differential Revision: https://phab.mercurial-scm.org/D3095
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36679
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
/*
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
 * xdiff.cc - fuzzer harness for thirdparty/xdiff
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
 *
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
 * Copyright 2018, Google Inc.
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
 *
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
 * This software may be used and distributed according to the terms of
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
 * the GNU General Public License, incorporated herein by reference.
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
 */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
#include "thirdparty/xdiff/xdiff.h"
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
#include <inttypes.h>
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
#include <stdlib.h>
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
extern "C" {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
int hunk_consumer(long a1, long a2, long b1, long b2, void *priv)
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
{
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
	// TODO: probably also test returning -1 from this when things break?
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
	return 0;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
}
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
{
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
	if (!Size) {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
		return 0;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
	}
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
	// figure out a random point in [0, Size] to split our input.
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
	size_t split = Data[0] / 255.0 * Size;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
	mmfile_t a, b;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
	// `a` input to diff is data[1:split]
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
	a.ptr = (char *)Data + 1;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
	// which has len split-1
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
	a.size = split - 1;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
	// `b` starts at the next byte after `a` ends
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
	b.ptr = a.ptr + a.size;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
	b.size = Size - split;
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
	xpparam_t xpp = {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
	    XDF_INDENT_HEURISTIC, /* flags */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
	};
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
	xdemitconf_t xecfg = {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
	    XDL_EMIT_BDIFFHUNK, /* flags */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
	    hunk_consumer,      /* hunk_consume_func */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
	};
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
	xdemitcb_t ecb = {
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
	    NULL, /* priv */
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
	};
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
	xdl_diff(&a, &b, &xpp, &xecfg, &ecb);
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    49
	return 0; // Non-zero return values are reserved for future use.
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
}
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    51
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
#ifdef HG_FUZZER_INCLUDE_MAIN
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
int main(int argc, char **argv)
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    54
{
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    55
	const char data[] = "asdf";
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    56
	return LLVMFuzzerTestOneInput((const uint8_t *)data, 4);
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    57
}
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    58
#endif
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    59
624cbd1477a6 fuzz: add a fuzzer for xdiff
Augie Fackler <augie@google.com>
parents:
diff changeset
    60
} // extern "C"