summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2009-01-29 00:56:34 -0500
committerLibravatar Junio C Hamano <gitster@pobox.com>2009-01-28 23:40:53 -0800
commit915308b187bdaba9ad1c6c3dea7b2b4b200b4796 (patch)
treec04697728ff54f8ee2fa8fdcdd4d92b258c7df20
parenttest-path-utils: Fix off by one, found by valgrind (diff)
downloadtgif-915308b187bdaba9ad1c6c3dea7b2b4b200b4796.tar.xz
avoid 31-bit truncation in write_loose_object
The size of the content we are adding may be larger than 2.1G (i.e., "git add gigantic-file"). Most of the code-path to do so uses size_t or unsigned long to record the size, but write_loose_object uses a signed int. On platforms where "int" is 32-bits (which includes x86_64 Linux platforms), we end up passing malloc a negative size. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--sha1_file.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 88035a0cd1..0cfea9edc1 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2280,7 +2280,8 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
void *buf, unsigned long len, time_t mtime)
{
- int fd, size, ret;
+ int fd, ret;
+ size_t size;
unsigned char *compressed;
z_stream stream;
char *filename;