Re: [PATCH] apply: fix segfault
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:13
Junio C Hamano [off-list ref] writes:
quoted hunk
Johannes Schindelin [off-list ref] writes:quoted
When the patch reports a line number that is larger than the number of lines in the current version of the file, git-apply used to segfault.I have to wonder if the correct fix should be like this instead. Under that condition, I think computation of the initial "try" value already oversteps the line[] array for the original image.diff --git a/builtin-apply.c b/builtin-apply.c index 2b8ba81..177f541 100644 --- a/builtin-apply.c +++ b/builtin-apply.c@@ -1809,6 +1809,9 @@ static int find_pos(struct image *img, else if (match_end) line = img->nr - preimage->nr; + if (line > preimage->nr) + line = preimage->nr; + try = 0; for (i = 0; i < line; i++) try += img->line[i].len;
Sorry, obviously the check should be against img->nr not the preimage.