Skip to content

Commit 60890cc

Browse files
ianamcleangitster
authored andcommitted
Fix "Out of memory? mmap failed" for files larger than 4GB on Windows
The git_mmap implementation was broken for file sizes that wouldn't fit into a size_t (32 bits). This was caused by intermediate variables that were only 32 bits wide when they should be 64 bits. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cc24a1d commit 60890cc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compat/win32mmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
44
{
55
HANDLE hmap;
66
void *temp;
7-
size_t len;
7+
off_t len;
88
struct stat st;
99
uint64_t o = offset;
1010
uint32_t l = o & 0xFFFFFFFF;
1111
uint32_t h = (o >> 32) & 0xFFFFFFFF;
1212

1313
if (!fstat(fd, &st))
14-
len = xsize_t(st.st_size);
14+
len = st.st_size;
1515
else
1616
die("mmap: could not determine filesize");
1717

1818
if ((length + offset) > len)
19-
length = len - offset;
19+
length = xsize_t(len - offset);
2020

2121
if (!(flags & MAP_PRIVATE))
2222
die("Invalid usage of mmap when built with USE_WIN32_MMAP");

0 commit comments

Comments
 (0)