git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.

Previous: Junio C Hamano
Message 4 of 4 in “apply: fix segfault”
  1. apply: fix segfaultJohannes Schindelin, Feb 11, 2008
  2. Junio C HamanoFeb 11, 2008
  3. Junio C HamanoFeb 11, 2008
  4. Junio C HamanoFeb 11, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.