public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: "Kyle J. McKay" <mackyle@gmail•com>
Cc: Michael Blume <blume.mike@gmail•com>, Git List <git@vger•kernel.org>
Subject: Re: Segmentation fault in git apply
Date: Fri, 16 Jan 2015 11:58:55 -0800	[thread overview]
Message-ID: <xmqqbnly1oqo.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <4157F6B0-DDF4-4F71-A09B-EE216537CA89@gmail.com> (Kyle J. McKay's message of "Thu, 15 Jan 2015 01:10:20 -0800")

"Kyle J. McKay" <mackyle@gmail•com> writes:

> If I make this change on top of 250b3c6c:
>
> diff --git a/builtin/apply.c b/builtin/apply.c
> index df773c75..8795e830 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -2390,6 +2390,8 @@ static int match_fragment(struct image *img,
>  	fixed_buf = strbuf_detach(&fixed, &fixed_len);
>  	if (postlen < postimage->len)
>  		postlen = 0;
> +	if (postlen)
> +		postlen = 2 * postimage->len;
>  	update_pre_post_images(preimage, postimage,
>  			       fixed_buf, fixed_len, postlen);
>  	return 1;
>
> Then the problem goes away.  That seems to suggest that postlen is
> being computed incorrectly, but someone more familiar with
> bulitin/apply.c is going to need to look at it.

Indeed, with this, the test case detects under-counting in the
caller (the caller counts 262 bytes but the expansion consumes 273
bytes).

-- >8 --
Subject: apply: make update_pre_post_images() sanity check the given postlen

---
 builtin/apply.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/builtin/apply.c b/builtin/apply.c
index 622ee16..18b7997 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -2174,6 +2174,10 @@ static void update_pre_post_images(struct image *preimage,
 	/* Fix the length of the whole thing */
 	postimage->len = new - postimage->buf;
 	postimage->nr -= reduced;
+
+	if (postlen && postlen < (new - postimage->buf))
+		die("BUG: postlen = %d, used = %d",
+		    (int)postlen, (int)(new - postimage->buf));
 }
 
 static int match_fragment(struct image *img,
-- 
2.3.0-rc0-149-g0286818

  reply	other threads:[~2015-01-16 19:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14 18:20 Segmentation fault in git apply Michael Blume
2015-01-14 18:40 ` Michael Blume
2015-01-14 18:44   ` Michael Blume
2015-01-14 18:48     ` Michael Blume
2015-01-14 18:58       ` Michael Blume
2015-01-14 19:09         ` Michael Blume
2015-01-15  8:26           ` Kyle J. McKay
2015-01-15  9:10             ` Kyle J. McKay
2015-01-16 19:58               ` Junio C Hamano [this message]
2015-01-16 23:54                 ` [PATCH] apply: count the size of postimage correctly Junio C Hamano
2015-01-18 10:49                   ` [PATCH] test: add git apply whitespace expansion tests Kyle J. McKay
2015-01-18 22:11                     ` Junio C Hamano
2015-01-19  3:54                       ` Kyle J. McKay
2015-01-21 22:33                         ` Junio C Hamano
2015-01-22  6:55                           ` Kyle J. McKay
2015-01-22 19:23                             ` Junio C Hamano
2015-01-23  0:12                               ` Kyle J. McKay
2015-01-22 22:58                           ` [PATCH v2 0/4] apply --whitespace=fix buffer corruption fix Junio C Hamano
2015-01-22 22:58                             ` [PATCH v2 1/4] apply.c: typofix Junio C Hamano
2015-01-22 23:17                               ` Stefan Beller
2015-01-22 23:42                                 ` Junio C Hamano
2015-01-22 23:48                                   ` Stefan Beller
2015-01-22 22:58                             ` [PATCH v2 2/4] apply: make update_pre_post_images() sanity check the given postlen Junio C Hamano
2015-01-22 22:58                             ` [PATCH v2 3/4] apply: count the size of postimage correctly Junio C Hamano
2015-01-22 22:58                             ` [PATCH v2 4/4] apply: detect and mark whitespace errors in context lines when fixing Junio C Hamano
2015-01-14 18:50 ` Segmentation fault in git apply Junio C Hamano

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=xmqqbnly1oqo.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=blume.mike@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=mackyle@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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