]>
git.proxmox.com Git - libgit2.git/blob - fuzzers/midx_fuzzer.c
2 * libgit2 multi-pack-index 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.
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_midx_file idx
= {{0}};
36 git_buf midx_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 packfile is somewhat valid.
47 append_hash
= *data
& 0x80;
48 /* Keep a 4-byte alignment to avoid unaligned accesses. */
53 if (git_buf_init(&midx_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(midx_buf
.ptr
, data
, size
);
60 memcpy(midx_buf
.ptr
+ size
, &oid
, sizeof(oid
));
62 git_buf_attach_notowned(&midx_buf
, (char *)data
, size
);
65 if (git_midx_parse(&idx
, (const unsigned char *)git_buf_cstr(&midx_buf
), git_buf_len(&midx_buf
)) < 0)
68 /* Search for any oid, just to exercise that codepath. */
69 if (git_midx_entry_find(&e
, &idx
, &oid
, GIT_OID_HEXSZ
) < 0)
74 git_buf_dispose(&midx_buf
);