Skip to content

Commit 915308b

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b8469ad commit 915308b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sha1_file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,8 @@ static int create_tmpfile(char *buffer, size_t bufsiz, const char *filename)
22802280
static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
22812281
void *buf, unsigned long len, time_t mtime)
22822282
{
2283-
int fd, size, ret;
2283+
int fd, ret;
2284+
size_t size;
22842285
unsigned char *compressed;
22852286
z_stream stream;
22862287
char *filename;

0 commit comments

Comments
 (0)