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>
This commit is contained in:
parent
166df26f28
commit
7171a0b0cf
@ -549,13 +549,13 @@ static void *unpack_data(struct object_entry *obj,
|
|||||||
void *cb_data)
|
void *cb_data)
|
||||||
{
|
{
|
||||||
off_t from = obj[0].idx.offset + obj[0].hdr_size;
|
off_t from = obj[0].idx.offset + obj[0].hdr_size;
|
||||||
unsigned long len = obj[1].idx.offset - from;
|
off_t len = obj[1].idx.offset - from;
|
||||||
unsigned char *data, *inbuf;
|
unsigned char *data, *inbuf;
|
||||||
git_zstream stream;
|
git_zstream stream;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
data = xmallocz(consume ? 64*1024 : obj->size);
|
data = xmallocz(consume ? 64*1024 : obj->size);
|
||||||
inbuf = xmalloc((len < 64*1024) ? len : 64*1024);
|
inbuf = xmalloc((len < 64*1024) ? (int)len : 64*1024);
|
||||||
|
|
||||||
memset(&stream, 0, sizeof(stream));
|
memset(&stream, 0, sizeof(stream));
|
||||||
git_inflate_init(&stream);
|
git_inflate_init(&stream);
|
||||||
@ -563,15 +563,15 @@ static void *unpack_data(struct object_entry *obj,
|
|||||||
stream.avail_out = consume ? 64*1024 : obj->size;
|
stream.avail_out = consume ? 64*1024 : obj->size;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ssize_t n = (len < 64*1024) ? len : 64*1024;
|
ssize_t n = (len < 64*1024) ? (ssize_t)len : 64*1024;
|
||||||
n = xpread(get_thread_data()->pack_fd, inbuf, n, from);
|
n = xpread(get_thread_data()->pack_fd, inbuf, n, from);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
die_errno(_("cannot pread pack file"));
|
die_errno(_("cannot pread pack file"));
|
||||||
if (!n)
|
if (!n)
|
||||||
die(Q_("premature end of pack file, %lu byte missing",
|
die(Q_("premature end of pack file, %"PRIuMAX" byte missing",
|
||||||
"premature end of pack file, %lu bytes missing",
|
"premature end of pack file, %"PRIuMAX" bytes missing",
|
||||||
len),
|
(unsigned int)len),
|
||||||
len);
|
(uintmax_t)len);
|
||||||
from += n;
|
from += n;
|
||||||
len -= n;
|
len -= n;
|
||||||
stream.next_in = inbuf;
|
stream.next_in = inbuf;
|
||||||
|
Loading…
Reference in New Issue
Block a user