From 1164f1e48d7c8ed613e8a371ecfce27220606e09 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 26 Jun 2007 14:34:02 -0700 Subject: [PATCH] Fix zero-object version-2 packs A pack-file can get created without any objects in it (to transfer "no data" - which can happen if you use a reference git repo, for example, or just otherwise just end up transferring only branch head information and already have all the objects themselves). And while we probably should never create an index for such a pack, if we do (and we do), the index file size sanity checking was incorrect. This fixes it. Reported-and-tested-by: Jocke Tjernlund Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- sha1_file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sha1_file.c b/sha1_file.c index c2f807f4c2..b9d07de156 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -509,7 +509,10 @@ static int check_packed_git_idx(const char *path, struct packed_git *p) * for offsets larger than 2^31. */ unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20; - if (idx_size < min_size || idx_size > min_size + (nr - 1)*8) { + unsigned long max_size = min_size; + if (nr) + max_size += (nr - 1)*8; + if (idx_size < min_size || idx_size > max_size) { munmap(idx_map, idx_size); return error("wrong index file size in %s", path); }