/src/libgit2/fuzzers/objects_fuzzer.c
Line | Count | Source (jump to first uncovered line) |
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 | | #include "standalone_driver.h" |
14 | | |
15 | 12 | #define UNUSED(x) (void)(x) |
16 | | |
17 | | int LLVMFuzzerInitialize(int *argc, char ***argv) |
18 | 6 | { |
19 | 6 | UNUSED(argc); |
20 | 6 | UNUSED(argv); |
21 | | |
22 | 6 | if (git_libgit2_init() < 0) |
23 | 0 | abort(); |
24 | | |
25 | 6 | return 0; |
26 | 6 | } |
27 | | |
28 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
29 | 2.01k | { |
30 | 2.01k | const git_object_t types[] = { |
31 | 2.01k | GIT_OBJECT_BLOB, GIT_OBJECT_TREE, GIT_OBJECT_COMMIT, GIT_OBJECT_TAG |
32 | 2.01k | }; |
33 | 2.01k | git_object *object = NULL; |
34 | 2.01k | size_t i; |
35 | | |
36 | | /* |
37 | | * Brute-force parse this as every object type. We want |
38 | | * to stress the parsing logic anyway, so this is fine |
39 | | * to do. |
40 | | */ |
41 | 10.0k | for (i = 0; i < ARRAY_SIZE(types); i++) { |
42 | 8.05k | if (git_object__from_raw(&object, (const char *) data, size, types[i], GIT_OID_SHA1) < 0) |
43 | 5.95k | continue; |
44 | 2.10k | git_object_free(object); |
45 | 2.10k | object = NULL; |
46 | 2.10k | } |
47 | | |
48 | 2.01k | return 0; |
49 | 2.01k | } |