4 static int verify_packfile(struct packed_git *p)
6 unsigned long index_size = p->index_size;
7 void *index_base = p->index_base;
9 unsigned char sha1[20];
10 unsigned long pack_size = p->pack_size;
12 struct pack_header *hdr;
16 if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
17 return error("Packfile signature mismatch", p->pack_name);
18 if (hdr->hdr_version != htonl(PACK_VERSION))
19 return error("Packfile version %d different from ours %d",
20 ntohl(hdr->hdr_version), PACK_VERSION);
21 nr_objects = ntohl(hdr->hdr_entries);
22 if (num_packed_objects(p) != nr_objects)
23 return error("Packfile claims to have %d objects, "
24 "while idx size expects %d", nr_objects,
25 num_packed_objects(p));
28 pack_base = p->pack_base;
29 SHA1_Update(&ctx, pack_base, pack_size - 20);
30 SHA1_Final(sha1, &ctx);
31 if (memcmp(sha1, index_base + index_size - 40, 20))
32 return error("Packfile %s SHA1 mismatch with idx",
34 if (memcmp(sha1, pack_base + pack_size - 20, 20))
35 return error("Packfile %s SHA1 mismatch with itself",
41 int verify_pack(struct packed_git *p)
43 unsigned long index_size = p->index_size;
44 void *index_base = p->index_base;
46 unsigned char sha1[20];
49 /* Verify SHA1 sum of the index file */
51 SHA1_Update(&ctx, index_base, index_size - 20);
52 SHA1_Final(sha1, &ctx);
53 if (memcmp(sha1, index_base + index_size - 20, 20))
54 return error("Packfile index for %s SHA1 mismatch",
57 /* Verify pack file */
59 ret = verify_packfile(p);