aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2006-08-21 03:10:02 -0400
committerJunio C Hamano <junkio@cox.net>2006-08-21 20:24:56 -0700
commitda7560110f91088ee2a664e98f75ff54e0d9e1e1 (patch)
treef2a7f6a19b897ec228d507a91d2f2c46741557e3 /sha1_file.c
parent7230e6d042ae385377f09c4d226d9b1aa7a2c13b (diff)
downloadgit-da7560110f91088ee2a664e98f75ff54e0d9e1e1.tar.gz
git-da7560110f91088ee2a664e98f75ff54e0d9e1e1.tar.xz
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>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 04f7f94d2..5f34c69d3 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -463,6 +463,7 @@ int use_packed_git(struct packed_git *p)
int fd;
struct stat st;
void *map;
+ struct pack_header *hdr;
pack_mapped += p->pack_size;
while (PACK_MAX_SZ < pack_mapped && unuse_one_packed_git())
@@ -482,6 +483,17 @@ int use_packed_git(struct packed_git *p)
die("packfile %s cannot be mapped.", p->pack_name);
p->pack_base = map;
+ /* Check if we understand this pack file. If we don't we're
+ * likely too old to handle it.
+ */
+ hdr = map;
+ if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
+ die("packfile %s isn't actually a pack.", p->pack_name);
+ if (!pack_version_ok(hdr->hdr_version))
+ die("packfile %s is version %i and not supported"
+ " (try upgrading GIT to a newer version)",
+ p->pack_name, ntohl(hdr->hdr_version));
+
/* Check if the pack file matches with the index file.
* this is cheap.
*/