[PATCH] avoid possible overflow in delta size filtering computation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On a 32-bit system, the maximum possible size for an object is less than 
4GB, while 64-bit systems may cope with larger objects.  Due to this 
limitation, variables holding object sizes are using an unsigned long 
type (32 bits on 32-bit systems, or 64 bits on 64-bit systems).

When large objects are encountered, and/or people play with large delta 
depth values, it is possible for the maximum allowed delta size 
computation to overflow, especially on a 32-bit system.  When this 
occurs, surviving result bits may represent a value much smaller than 
what it is supposed to be, or even zero.  This prevents some objects 
from being deltified although they do get deltified when a smaller depth 
limit is used.  Fix this by always performing a 64-bit multiplication.

Signed-off-by: Nicolas Pitre <nico@xxxxxxx>

diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 3a4bdbb..9fc3b35 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -1293,7 +1293,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
 		max_size = trg_entry->delta_size;
 		ref_depth = trg->depth;
 	}
-	max_size = max_size * (max_depth - src->depth) /
+	max_size = (uint64_t)max_size * (max_depth - src->depth) /
 						(max_depth - ref_depth + 1);
 	if (max_size == 0)
 		return 0;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux