From 720fe22d50a58e3308124ec7f5b0fa6c17be3d22 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Tue, 24 Mar 2009 15:56:12 -0400 Subject: 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 Signed-off-by: Junio C Hamano diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index fb5e14d..84a13c7 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1265,7 +1265,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; -- cgit v0.10.2-6-g49f6 From e8bd78c3fcba35b8344ea6bab6218b793e507ea3 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 24 Mar 2009 12:31:36 -0700 Subject: close_sha1_file(): make it easier to diagnose errors A bug report with "unable to write sha1 file" made us realize that we do not have enough information to guess why close() is failing. Signed-off-by: Junio C Hamano diff --git a/sha1_file.c b/sha1_file.c index bea958e..bcfcab3 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2241,7 +2241,7 @@ static void close_sha1_file(int fd) fsync_or_die(fd, "sha1 file"); fchmod(fd, 0444); if (close(fd) != 0) - die("unable to write sha1 file"); + die("error when closing sha1 file (%s)", strerror(errno)); } /* Size of directory component, including the ending '/' */ -- cgit v0.10.2-6-g49f6 From 389d17677187f5e996022b7b8e0faf800608cb3a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 24 Mar 2009 16:10:35 -0700 Subject: Increase the size of the die/warning buffer to avoid truncation Long messages like those from lockfile.c when a lock can't be obtained truncate with only 256 bytes in the message buffer. Bump it to 1024 to give more space for these longer cases. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano diff --git a/usage.c b/usage.c index 24f5fc0..820d09f 100644 --- a/usage.c +++ b/usage.c @@ -7,7 +7,7 @@ static void report(const char *prefix, const char *err, va_list params) { - char msg[256]; + char msg[1024]; vsnprintf(msg, sizeof(msg), err, params); fprintf(stderr, "%s%s\n", prefix, msg); } -- cgit v0.10.2-6-g49f6