@matheusbsbs / matheus-bagliano / commits / da7560110f
Fork 0

Verify we know how to read a pack before trying to using it.

If the pack format were to ever change or be extended in the future there is no assurance that just because the pack file lives in objects/pack and doesn't end in .idx that we can read and decompress its contents properly. If we encounter what we think is a pack file and it isn't or we don't recognize its version then die and suggest to the user that they upgrade to a newer version of GIT which can handle that pack file. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn Pearce committed Aug 21, 2006 at 03:10 UTC da7560110f91088ee2a664e98f75ff54e0d9e1e1
1 file changed +12
sha1_file.c
+12
@@ -463,6 +463,7 @@ int use_packed_git(struct packed_git *p)
463 int fd;
464 struct stat st;
465 void *map;
466 + struct pack_header *hdr;
467
468 pack_mapped += p->pack_size;
469 while (PACK_MAX_SZ < pack_mapped && unuse_one_packed_git())
@@ -482,6 +483,17 @@ int use_packed_git(struct packed_git *p)
483 die("packfile %s cannot be mapped.", p->pack_name);
484 p->pack_base = map;
485
486 + /* Check if we understand this pack file. If we don't we're
487 + * likely too old to handle it.
488 + */
489 + hdr = map;
490 + if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
491 + die("packfile %s isn't actually a pack.", p->pack_name);
492 + if (!pack_version_ok(hdr->hdr_version))
493 + die("packfile %s is version %i and not supported"
494 + " (try upgrading GIT to a newer version)",
495 + p->pack_name, ntohl(hdr->hdr_version));
496 +
497 /* Check if the pack file matches with the index file.
498 * this is cheap.
499 */