mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
object: test looking up truncated objects
Add a test that looks up an invalid, truncated object, that is shorter than the advertised length.
This commit is contained in:
@@ -120,3 +120,14 @@ void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void)
|
||||
git_str_dispose(&oldpath);
|
||||
git_str_dispose(&newpath);
|
||||
}
|
||||
|
||||
void test_object_lookup__lookup_short_object_errors_gracefully(void)
|
||||
{
|
||||
const char *invalid = "bf3d798a12d2bd09a73b1bbdec6fde6f9836f9ac";
|
||||
git_object *object;
|
||||
git_oid oid;
|
||||
|
||||
cl_git_pass(git_oid_from_string(&oid, invalid, GIT_OID_SHA1));
|
||||
|
||||
cl_git_fail(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_BLOB));
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ static int foreach_cb(const git_oid *oid, void *data)
|
||||
|
||||
/*
|
||||
* $ git --git-dir tests/resources/testrepo.git count-objects --verbose
|
||||
* count: 60
|
||||
* size: 240
|
||||
* count: 61
|
||||
* size: 244
|
||||
* in-pack: 1640
|
||||
* packs: 3
|
||||
* size-pack: 425
|
||||
@@ -43,7 +43,7 @@ void test_odb_foreach__foreach(void)
|
||||
git_repository_odb(&_odb, _repo);
|
||||
|
||||
cl_git_pass(git_odb_foreach(_odb, foreach_cb, &nobj));
|
||||
cl_assert_equal_i(60 + 1640, nobj); /* count + in-pack */
|
||||
cl_assert_equal_i(61 + 1640, nobj); /* count + in-pack */
|
||||
}
|
||||
|
||||
void test_odb_foreach__one_pack(void)
|
||||
@@ -144,7 +144,7 @@ void test_odb_foreach__files_in_objects_dir(void)
|
||||
|
||||
cl_git_pass(git_repository_odb(&odb, repo));
|
||||
cl_git_pass(git_odb_foreach(odb, foreach_cb, &nobj));
|
||||
cl_assert_equal_i(60 + 1640, nobj); /* count + in-pack */
|
||||
cl_assert_equal_i(61 + 1640, nobj); /* count + in-pack */
|
||||
|
||||
git_odb_free(odb);
|
||||
git_repository_free(repo);
|
||||
|
||||
BIN
tests/resources/testrepo.git/objects/bf/3d798a12d2bd09a73b1bbdec6fde6f9836f9ac
vendored
Normal file
BIN
tests/resources/testrepo.git/objects/bf/3d798a12d2bd09a73b1bbdec6fde6f9836f9ac
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user