2 * libgit2 commit-graph fuzzer target.
4 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
18 #include "commit_graph.h"
20 int LLVMFuzzerInitialize(int *argc
, char ***argv
)
25 if (git_libgit2_init() < 0) {
26 fprintf(stderr
, "Failed to initialize libgit2\n");
32 int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
)
34 git_commit_graph_file file
= {{0}};
35 git_commit_graph_entry e
;
36 git_buf commit_graph_buf
= GIT_BUF_INIT
;
38 bool append_hash
= false;
44 * If the first byte in the stream has the high bit set, append the
45 * SHA1 hash so that the file is somewhat valid.
47 append_hash
= *data
& 0x80;
48 /* Keep a 4-byte alignment to avoid unaligned accesses. */
53 if (git_buf_init(&commit_graph_buf
, size
+ sizeof(oid
)) < 0)
55 if (git_hash_buf(&oid
, data
, size
) < 0) {
56 fprintf(stderr
, "Failed to compute the SHA1 hash\n");
59 memcpy(commit_graph_buf
.ptr
, data
, size
);
60 memcpy(commit_graph_buf
.ptr
+ size
, &oid
, sizeof(oid
));
62 git_buf_attach_notowned(&commit_graph_buf
, (char *)data
, size
);
65 if (git_commit_graph_file_parse(
67 (const unsigned char *)git_buf_cstr(&commit_graph_buf
),
68 git_buf_len(&commit_graph_buf
))
72 /* Search for any oid, just to exercise that codepath. */
73 if (git_commit_graph_entry_find(&e
, &file
, &oid
, GIT_OID_HEXSZ
) < 0)
77 git_commit_graph_file_close(&file
);
78 git_buf_dispose(&commit_graph_buf
);