git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] avoid possible overflow in delta size filtering computation
@ 2009-03-24 19:56 Nicolas Pitre
  2009-03-24 20:20 ` Brandon Casey
  2009-03-25 12:15 ` Kjetil Barvik
  0 siblings, 2 replies; 10+ messages in thread
From: Nicolas Pitre @ 2009-03-24 19:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Kjetil Barvik, git

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@cam.org>

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;

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-03-27  2:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-24 19:56 [PATCH] avoid possible overflow in delta size filtering computation Nicolas Pitre
2009-03-24 20:20 ` Brandon Casey
2009-03-24 20:52   ` Nicolas Pitre
2009-03-25  0:39   ` Nicolas Pitre
2009-03-25 12:15 ` Kjetil Barvik
2009-03-25 16:18   ` Nicolas Pitre
2009-03-25 16:34     ` Kjetil Barvik
2009-03-25 19:17       ` Nicolas Pitre
2009-03-26  7:18         ` Kjetil Barvik
2009-03-27  2:23           ` Nicolas Pitre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).