]> git.ipfire.org Git - thirdparty/git.git/commitdiff
verify_packfile: check pack validity before accessing data
authorJeff King <peff@peff.net>
Thu, 22 Sep 2016 03:49:05 +0000 (23:49 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Sep 2016 18:18:13 +0000 (11:18 -0700)
The verify_packfile() does not explicitly open the packfile;
instead, it starts with a sha1 checksum over the whole pack,
and relies on use_pack() to open the packfile as a side
effect.

If the pack cannot be opened for whatever reason (either
because its header information is corrupted, or perhaps
because a simultaneous repack deleted it), then use_pack()
will die(), as it has no way to return an error. This is not
ideal, as verify_packfile() otherwise tries to gently return
an error (this lets programs like git-fsck go on to check
other packs).

Instead, let's check is_pack_valid() up front, and return an
error if it fails. This will open the pack as a side effect,
and then use_pack() will later rely on our cached
descriptor, and avoid calling die().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-check.c

index 1da89a41cec9e605fc3fdfa8efaaf2489e501c88..5af987c09b108740b766d6fe9db400a53c01dd7e 100644 (file)
@@ -57,11 +57,8 @@ static int verify_packfile(struct packed_git *p,
        int err = 0;
        struct idx_entry *entries;
 
-       /* Note that the pack header checks are actually performed by
-        * use_pack when it first opens the pack file.  If anything
-        * goes wrong during those checks then the call will die out
-        * immediately.
-        */
+       if (!is_pack_valid(p))
+               return error("packfile %s cannot be accessed", p->pack_name);
 
        git_SHA1_Init(&ctx);
        do {