Skip to content

Commit a9445d8

Browse files
peffgitster
authored andcommitted
verify_packfile: check pack validity before accessing data
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b65a8d commit a9445d8

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

pack-check.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ static int verify_packfile(struct packed_git *p,
5757
int err = 0;
5858
struct idx_entry *entries;
5959

60-
/* Note that the pack header checks are actually performed by
61-
* use_pack when it first opens the pack file. If anything
62-
* goes wrong during those checks then the call will die out
63-
* immediately.
64-
*/
60+
if (!is_pack_valid(p))
61+
return error("packfile %s cannot be accessed", p->pack_name);
6562

6663
git_SHA1_Init(&ctx);
6764
do {

0 commit comments

Comments
 (0)