From: Junio C Hamano <gitster@pobox.com>
To: "Kyle J. McKay" <mackyle@gmail.com>
Cc: Git mailing list <git@vger.kernel.org>,
Michael Blume <blume.mike@gmail.com>
Subject: Re: [PATCH] test: add git apply whitespace expansion tests
Date: Thu, 22 Jan 2015 11:23:32 -0800 [thread overview]
Message-ID: <xmqq7fwetya3.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <21FC5344-64BF-46B1-ADA9-DDE3B1FEC8C4@gmail.com> (Kyle J. McKay's message of "Wed, 21 Jan 2015 22:55:05 -0800")
"Kyle J. McKay" <mackyle@gmail.com> writes:
> On Jan 21, 2015, at 14:33, Junio C Hamano wrote:
>
>> "Kyle J. McKay" <mackyle@gmail.com> writes:
>>
>>> So since I've not been able to get test 2 or 3 to core dump (even
>>> before 250b3c6c) I tend to believe you are correct in that the code
>>> thinks (incorrectly) that the result should fit within the buffer.
>>
>> Thanks; let me steal your tests when I reroll.
>
> Awesome. :)
>
> But please squash in this tiny change if using the tests verbatim:
Thanks. I actually have a question wrt the need for $MAKE_PATCHES.
It would have been more natural to do something like:
test_expect_success 'setup' '
printf "\t%s\n" 1 2 3 4 5 6 >before &&
printf "\t%s\n" 1 2 3 >after &&
printf "%64s\n" a b c >>after &&
printf "\t%s\n" 4 5 6 >>after &&
git diff --no-index before after |
sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch &&
printf "%64s\n" 1 2 3 4 5 6 >test-1 &&
printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
printf "\t%s\n" a b c d e f >before &&
printf "\t%s\n" a b c >after &&
...
cat test-4 >expect-4 &&
printf "%64s\n" a b c >>expect-4 &&
while test $x -lt 100
do
printf "%63s%02d\n" "" $x >>test-4
printf "%63s%02d\n" "" $x >>expect-4
x=$(( $x + 1 ))
done &&
git config core.whitespace tab-in-indent,tabwidth=63 &&
git config apply.whitespace fix
'
test_expect_success 'apply with ws expansion (1)' '
git apply patch1.patch &&
test_cmp test-1 expect-1
'
and if you want test files you can just skip tests #2 and later,
without introducing an ad-hoc mechanism like you did.
Was there something more than that that you wanted from
$MAKE_PATCHES?
In any case, here is an update to that sanity check patch to catch
the two cases the BUG did not trigger.
Sometimes the caller under-counted the size of the result but
thought that it would still fit within the original (hence allowing
us to update in-place by passing postlen==0) but the actual result
was larger than the space we have allocated in the postimage,
clobbering the piece of memory after the postimage->buf.
diff --git a/builtin/apply.c b/builtin/apply.c
index 31f8733..3b7ba63 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -2171,6 +2171,12 @@ static void update_pre_post_images(struct image *preimage,
ctx++;
}
+ if (postlen
+ ? postlen < new - postimage->buf
+ : postimage->len < new - postimage->buf)
+ die("BUG: caller miscounted postlen: asked %d, orig = %d, used = %d",
+ (int)postlen, (int) postimage->len, (int)(new - postimage->buf));
+
/* Fix the length of the whole thing */
postimage->len = new - postimage->buf;
postimage->nr -= reduced;
next prev parent reply other threads:[~2015-01-22 19:23 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
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 [this message]
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=xmqq7fwetya3.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=blume.mike@gmail.com \
--cc=git@vger.kernel.org \
--cc=mackyle@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.