From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Bernhard Posselt <mail@bernhard-posselt.com>, git@vger.kernel.org
Subject: Re: Memory corruption when rebasing with git version 1.8.1.5 on arch
Date: Fri, 22 Mar 2013 17:24:21 -0400 [thread overview]
Message-ID: <20130322212421.GA5079@sigill.intra.peff.net> (raw)
In-Reply-To: <7vip4j71dw.fsf@alter.siamese.dyndns.org>
On Fri, Mar 22, 2013 at 11:08:59AM -0700, Junio C Hamano wrote:
> 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:
> @@ -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
prev parent reply other threads:[~2013-03-22 21:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-08 12:19 Memory corruption when rebasing with git version 1.8.1.5 on arch Bernhard Posselt
2013-03-08 21:28 ` Jeff King
2013-03-09 0:08 ` Bernhard Posselt
2013-03-09 4:48 ` Jeff King
2013-03-09 10:54 ` Bernhard Posselt
2013-03-10 7:05 ` Jeff King
2013-03-10 11:04 ` Bernhard Posselt
2013-03-10 11:45 ` Bernhard Posselt
2013-03-11 5:18 ` Jeff King
2013-03-19 10:42 ` Bernhard Posselt
2013-03-19 13:44 ` Jeff King
2013-03-19 16:02 ` Junio C Hamano
2013-03-22 18:08 ` Junio C Hamano
2013-03-22 21:24 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130322212421.GA5079@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mail@bernhard-posselt.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).