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

Re: Memory corruption when rebasing with git version 1.8.1.5 on arch

From
Jeff King <peff@peff.net>
Date
Mar 22, 2013, 21:24 UTC
Message-ID
<20130322212421.GA5079@sigill.intra.peff.net>
In-Reply-To
<7vip4j71dw.fsf@alter.siamese.dyndns.org>
On Fri, Mar 22, 2013 at 11:08:59AM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> This may be sufficient.  In the olden days, we relied on that all
> whitespace fixing rules made the result shorter and took advantage
> of it in update-pre-post-images to rewrite the images in place.  The
> oddball tab-in-indent (aka Python), however, can grow the result by
> expanding tabs (deemed "incorrect") in the input into runs of spaces
> (deemed "kosher").
> 
> Fortunately, we already support its more generalized form "match
> while ignoring whitespace differences" that can lengthen the result;
> as long as we correctly count the number of bytes needed to hold
> rewritten postimage, the existing logic in update_pre_post_images
> should be able to do the rest for us.

Yeah, your patch looks right to me. I do wonder if the optimization here:

Show 9 quoted lines
> @@ -2399,8 +2401,10 @@ static int match_fragment(struct image *img,
>  	 * hunk match.  Update the context lines in the postimage.
>  	 */
>  	fixed_buf = strbuf_detach(&fixed, &fixed_len);
> +	if (postlen < postimage->len)
> +		postlen = 0;
>  	update_pre_post_images(preimage, postimage,
> -			       fixed_buf, fixed_len, 0);
> +			       fixed_buf, fixed_len, postlen);

should simply go into update_pre_post_images (i.e., let it decide on whether to do it inline or with a new allocation, rather than making postlen==0 special). That would let the ignore-whitespace code path use the optimization, too (when it's possible).

By the way, I notice that when update_pre_post_images does allocate, the old value of postimage->buf is lost. It looks like that is not leaked, because it was pointing to a strbuf (newlines in apply_one_fragment) that we are going to release anyway afterwards. But that means nobody is freeing postimage->buf, which means that our newly malloc'd version is getting leaked.

-Peff
Previous: Junio C Hamano
Message 14 of 14 in “Memory corruption when rebasing with git version 1.8.1.5 on arch”
  1. Bernhard PosseltMar 8, 2013
  2. Jeff KingMar 8, 2013
  3. Bernhard PosseltMar 9, 2013
  4. Jeff KingMar 9, 2013
  5. Bernhard PosseltMar 9, 2013
  6. Jeff KingMar 10, 2013
  7. Bernhard PosseltMar 10, 2013
  8. Bernhard PosseltMar 10, 2013
  9. Jeff KingMar 11, 2013
  10. Bernhard PosseltMar 19, 2013
  11. Jeff KingMar 19, 2013
  12. Junio C HamanoMar 19, 2013
  13. Junio C HamanoMar 22, 2013
  14. Jeff KingMar 22, 2013

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.