]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-objects: pass length to check_pack_crc() without truncation
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Tue, 5 Jul 2016 17:05:54 +0000 (19:05 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 Jul 2016 17:14:29 +0000 (10:14 -0700)
On 32 bit systems with large file support, unsigned long is 32-bit
while the two offsets in the subtraction expression (pack-objects has
the exact same expression as in sha1_file.c but not shown in diff) are
in 64-bit. If an in-pack object is larger than 2^32 len/datalen is
truncated and we get a misleading "error: bad packed object CRC for
..." as a result.

Use off_t for len and datalen. check_pack_crc() already accepts this
argument as off_t and can deal with 4+ GB.

Noticed-by: Christoph Michelbach <michelbach94@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c
sha1_file.c

index b6664ce4d8d72cde05e1f1be5edcd967f003f0ef..a3a98c57410b0a32ed85c87013f8bd682af3a75a 100644 (file)
@@ -349,7 +349,7 @@ static unsigned long write_reuse_object(struct sha1file *f, struct object_entry
        struct revindex_entry *revidx;
        off_t offset;
        enum object_type type = entry->type;
-       unsigned long datalen;
+       off_t datalen;
        unsigned char header[10], dheader[10];
        unsigned hdrlen;
 
index d0f2aa029b14451d4ffe669d48602c55060b9f42..cd9b560e70bb6222d3977d16d9c7f1da101fd571 100644 (file)
@@ -2282,7 +2282,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
 
                if (do_check_packed_object_crc && p->index_version > 1) {
                        struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
-                       unsigned long len = revidx[1].offset - obj_offset;
+                       off_t len = revidx[1].offset - obj_offset;
                        if (check_pack_crc(p, &w_curs, obj_offset, len, revidx->nr)) {
                                const unsigned char *sha1 =
                                        nth_packed_object_sha1(p, revidx->nr);