Skip to content

Commit 46be82d

Browse files
trastgitster
authored andcommitted
xsize_t: check whether we lose bits
Attempting to mmap (via git-add or similar) a file larger than 4GB on 32-bit Linux systems results in a repository that has only the file modulo 4GB stored, because of truncation of the off_t file size to a size_t for mmap. When xsize_t was introduced to handle this truncation in dc49cd7 (Cast 64 bit off_t to 32 bit size_t, 2007-03-06), Shawn even pointed out that it should detect when such a cutoff happens. Make it so. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc49cd7 commit 46be82d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

git-compat-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ static inline ssize_t xwrite(int fd, const void *buf, size_t len)
260260

261261
static inline size_t xsize_t(off_t len)
262262
{
263+
if (len > (size_t) len)
264+
die("Cannot handle files this big");
263265
return (size_t)len;
264266
}
265267

0 commit comments

Comments
 (0)