Commit de53972f by Patrick Steinhardt

fuzzers: avoid use of libgit2 internals in packfile_raw

The packfile_raw fuzzer is using some internal APIs from libgit2, which
makes it hard to compile it as part of the oss-fuzz project. As oss-fuzz
requires us to link against the C++ FuzzingEngine library, we cannot use
"-DBUILD_FUZZERS=ON" directly but instead have to first compile an
object from our fuzzers and then link against the C++ library. Compiling
the fuzzer objects thus requires an external invocation of CC, and we
certainly don't want to do further black magic by adding libgit2's
private source directory to the header include path.

To fix the issue, convert the code to not use any internal APIs. Besides
some headers which we have to add now, this also requires us to change
to the hashing function of the ODB. Note that this will change the
hashing result, as we have previously not prepended the object header to
the data that is to be hashed. But this shouldn't matter in practice, as
we don't care for the hash value anyway.
parent 12804c46
......@@ -10,12 +10,14 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
#include "fileops.h"
#include "hash.h"
#include "git2.h"
#include "git2/sys/mempack.h"
#define UNUSED(x) (void)(x)
static git_odb *odb = NULL;
static git_odb_backend *mempack = NULL;
......@@ -25,8 +27,8 @@ static const unsigned int base_obj_len = 2;
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
GIT_UNUSED(argc);
GIT_UNUSED(argv);
UNUSED(argc);
UNUSED(argv);
if (git_libgit2_init() < 0) {
fprintf(stderr, "Failed to initialize libgit2\n");
abort();
......@@ -87,7 +89,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto cleanup;
if (append_hash) {
git_oid oid;
if (git_hash_buf(&oid, data, size) < 0) {
if (git_odb_hash(&oid, data, size, GIT_OBJ_BLOB) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment