Re: [PATCH] apply: fix segfault
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 11, 2008, 23:48 UTC
- Message-ID
- <7vejbj6oms.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <7vprv36qkt.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 24 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: > >> 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.