Skip to content

Commit

Permalink
Seek back to current filepos when mmap()ing with NO_MMAP
Browse files Browse the repository at this point in the history
"git-index-pack --fix-thin" relies on mmap() not changing the current
file position (otherwise the pack will be corrupted when writing the
final SHA1). Meet that expectation.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Nov 15, 2006
1 parent e267c2f commit 0a3881d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compat/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_t offset)
{
int n = 0;
off_t current_offset = lseek(fd, 0, SEEK_CUR);

if (start != NULL || !(flags & MAP_PRIVATE))
die("Invalid usage of gitfakemmap.");
Expand Down Expand Up @@ -39,6 +40,11 @@ void *gitfakemmap(void *start, size_t length, int prot , int flags, int fd, off_
n += count;
}

if (current_offset != lseek(fd, current_offset, SEEK_SET)) {
errno = EINVAL;
return MAP_FAILED;
}

return start;
}

Expand Down

0 comments on commit 0a3881d

Please sign in to comment.