Skip to content

Commit 7171a0b

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 166df26 commit 7171a0b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

builtin/index-pack.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,29 +549,29 @@ static void *unpack_data(struct object_entry *obj,
549549
void *cb_data)
550550
{
551551
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;
553553
unsigned char *data, *inbuf;
554554
git_zstream stream;
555555
int status;
556556

557557
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);
559559

560560
memset(&stream, 0, sizeof(stream));
561561
git_inflate_init(&stream);
562562
stream.next_out = data;
563563
stream.avail_out = consume ? 64*1024 : obj->size;
564564

565565
do {
566-
ssize_t n = (len < 64*1024) ? len : 64*1024;
566+
ssize_t n = (len < 64*1024) ? (ssize_t)len : 64*1024;
567567
n = xpread(get_thread_data()->pack_fd, inbuf, n, from);
568568
if (n < 0)
569569
die_errno(_("cannot pread pack file"));
570570
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);
575575
from += n;
576576
len -= n;
577577
stream.next_in = inbuf;

0 commit comments

Comments
 (0)