]> git.proxmox.com Git - libgit2.git/blob - fuzzers/objects_fuzzer.c
Merge branch 'debian/experimental' into debian/sid
[libgit2.git] / fuzzers / objects_fuzzer.c
1 /*
2 * libgit2 packfile fuzzer target.
3 *
4 * Copyright (C) the libgit2 contributors. All rights reserved.
5 *
6 * This file is part of libgit2, distributed under the GNU GPL v2 with
7 * a Linking Exception. For full terms see the included COPYING file.
8 */
9
10 #include "git2.h"
11 #include "object.h"
12
13 #define UNUSED(x) (void)(x)
14
15 int LLVMFuzzerInitialize(int *argc, char ***argv)
16 {
17 UNUSED(argc);
18 UNUSED(argv);
19
20 if (git_libgit2_init() < 0)
21 abort();
22
23 return 0;
24 }
25
26 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
27 {
28 const git_object_t types[] = {
29 GIT_OBJECT_BLOB, GIT_OBJECT_TREE, GIT_OBJECT_COMMIT, GIT_OBJECT_TAG
30 };
31 git_object *object = NULL;
32 size_t i;
33
34 /*
35 * Brute-force parse this as every object type. We want
36 * to stress the parsing logic anyway, so this is fine
37 * to do.
38 */
39 for (i = 0; i < ARRAY_SIZE(types); i++) {
40 if (git_object__from_raw(&object, (const char *) data, size, types[i]) < 0)
41 continue;
42 git_object_free(object);
43 object = NULL;
44 }
45
46 return 0;
47 }