index-pack: correct "len" type in unpack_data()

On 32-bit systems with large file support, one entry could be larger than 4GB and overflow "len". Correct it so we can unpack a full entry. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jul 13, 2016 at 17:44 UTC 7171a0b0cf5792fd549b601c84b274cd5e4155ed
1 file changed +7 -7
builtin/index-pack.c
+7 -7
@@ -549,13 +549,13 @@ static void *unpack_data(struct object_entry *obj,
549 void *cb_data)
550 {
551 off_t from = obj[0].idx.offset + obj[0].hdr_size;
552 - unsigned long len = obj[1].idx.offset - from;
552 + off_t len = obj[1].idx.offset - from;
553 unsigned char *data, *inbuf;
554 git_zstream stream;
555 int status;
556
557 data = xmallocz(consume ? 64*1024 : obj->size);
558 - inbuf = xmalloc((len < 64*1024) ? len : 64*1024);
558 + inbuf = xmalloc((len < 64*1024) ? (int)len : 64*1024);
559
560 memset(&stream, 0, sizeof(stream));
561 git_inflate_init(&stream);
@@ -563,15 +563,15 @@ static void *unpack_data(struct object_entry *obj,
563 stream.avail_out = consume ? 64*1024 : obj->size;
564
565 do {
566 - ssize_t n = (len < 64*1024) ? len : 64*1024;
566 + ssize_t n = (len < 64*1024) ? (ssize_t)len : 64*1024;
567 n = xpread(get_thread_data()->pack_fd, inbuf, n, from);
568 if (n < 0)
569 die_errno(_("cannot pread pack file"));
570 if (!n)
571 - die(Q_("premature end of pack file, %lu byte missing",
572 - "premature end of pack file, %lu bytes missing",
573 - len),
574 - len);
571 + die(Q_("premature end of pack file, %"PRIuMAX" byte missing",
572 + "premature end of pack file, %"PRIuMAX" bytes missing",
573 + (unsigned int)len),
574 + (uintmax_t)len);
575 from += n;
576 len -= n;
577 stream.next_in = inbuf;