Skip to content

Commit 1164f1e

Browse files
torvaldsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 582c739 commit 1164f1e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sha1_file.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,10 @@ static int check_packed_git_idx(const char *path, struct packed_git *p)
509509
* for offsets larger than 2^31.
510510
*/
511511
unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20;
512-
if (idx_size < min_size || idx_size > min_size + (nr - 1)*8) {
512+
unsigned long max_size = min_size;
513+
if (nr)
514+
max_size += (nr - 1)*8;
515+
if (idx_size < min_size || idx_size > max_size) {
513516
munmap(idx_map, idx_size);
514517
return error("wrong index file size in %s", path);
515518
}

0 commit comments

Comments
 (0)