summaryrefslogtreecommitdiff
path: root/src/diff_output.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-01-08 17:11:11 -0800
committerRussell Belfer <rb@github.com>2013-01-08 17:11:11 -0800
commitde590550172c68bf374f9d12636b06295c5fe048 (patch)
tree3bf0c7ca4b554784de72063b25933775308fb512 /src/diff_output.c
parentf7e4a7c2d5e314fe50fee851263e4ed6cfaa49ae (diff)
downloadlibgit2-de590550172c68bf374f9d12636b06295c5fe048.tar.gz
Resolve crash with diff against empty file
It is not legal inside our `p_mmap` function to mmap a zero length file. This adds a test that exercises that case inside diff and fixes the code path where we would try to do that. The fix turns out not to be a lot of code since our default file content is already initialized to "" which works in this case. Fixes #1210
Diffstat (limited to 'src/diff_output.c')
-rw-r--r--src/diff_output.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/diff_output.c b/src/diff_output.c
index e80cfaa84..f98665dfb 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -376,6 +376,9 @@ static int get_workdir_content(
goto close_and_cleanup;
if (error == 0) { /* note: git_filters_load returns filter count */
+ if (!file->size)
+ goto close_and_cleanup;
+
error = git_futils_mmap_ro(map, fd, 0, (size_t)file->size);
file->flags |= GIT_DIFF_FILE_UNMAP_DATA;
} else {