Skip to content

Commit 720fe22

Browse files
Nicolas Pitregitster
authored andcommitted
avoid possible overflow in delta size filtering computation
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3e5970a commit 720fe22

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin-pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
12651265
max_size = trg_entry->delta_size;
12661266
ref_depth = trg->depth;
12671267
}
1268-
max_size = max_size * (max_depth - src->depth) /
1268+
max_size = (uint64_t)max_size * (max_depth - src->depth) /
12691269
(max_depth - ref_depth + 1);
12701270
if (max_size == 0)
12711271
return 0;

0 commit comments

Comments
 (0)