From: Taylor Blau <me@ttaylorr.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Christian Couder <christian.couder@gmail.com>,
git@vger.kernel.org,
Matthias Buehlmann <Matthias.Buehlmann@mabulous.com>,
Jonathan Tan <jonathantanmy@google.com>
Subject: Re: Bug Report: Multi-line trailers containing empty lines break parsing
Date: Tue, 16 Feb 2021 13:07:46 -0500 [thread overview]
Message-ID: <YCwJ8tORQg2Air4r@nand.local> (raw)
In-Reply-To: <xmqqczx0sq1o.fsf@gitster.c.googlers.com>
On Mon, Feb 15, 2021 at 06:29:55PM -0800, Junio C Hamano wrote:
> Matthias Buehlmann <Matthias.Buehlmann@mabulous.com> writes:
>
> > Thank you for filling out a Git bug report!
> > Please answer the following questions to help us understand your issue.
>
> Thanks; let's ping our resident trailers expert ;-)
I'm not Christian, but hopefully I'm an OK substitute :).
I originally thought that this was an ambiguous test, since you could
reasonably say the trailers begin after the blank line in the second
"MultiLineTrailer" block. In that case, neither of the following lines
look like a trailer, so 'git interpret-trailers' could reasonably print
nothing.
But I was being tricked, since I looked at "test.txt" in my editor,
which automatically replaces blank lines (zero or more space characters
ending in a newline) with a single newline. In fact, this isn't
ambiguous at all, since the blank lines are continuations (they are a
single space character and then a newline):
00000090 65 64 20 6d 75 6c 74 69 2d 6c 69 6e 65 0a 20 74 |ed multi-line. t|
000000a0 72 61 69 6c 65 72 20 77 68 69 63 68 0a 20 0a 20 |railer which. . |
(see the repeated '0a 20' space + newline pair after "which").
I think that this is a legitimate bug in 'interpret-trailers' that it
doesn't know to continue multi-line trailers that have empty lines in
them.
I thought that this might have dated back to 022349c3b0 (trailer: avoid
unnecessary splitting on lines, 2016-11-02), but checking out that
commit's first parent shows the bug (albeit without --parse, which
didn't exist then).
Anyway, I'm pretty sure the problem is that
trailer.c:find_trailer_start() doesn't disambiguate between a blank line
and one that contains only space characters.
This patch might do the trick:
--- 8< ---
Subject: [PATCH] trailer.c: handle empty continuation lines
In a multi-line trailer, it is possible to have a continuation line
which contains at least one space character, terminating in a newline.
In this case, the trailer should continue across the blank continuation
line, but 'trailer.c:find_trailer_start()' handles this case
incorrectly.
When it encounters a blank line, find_trailer_start() assumes that the
trailers must begin on the line following the one it's looking at. But
this isn't the case if the line is a non-empty continuation, in which
the line may be part of a trailer.
Fix this by only considering a blank line which has exactly zero space
characters before the LF as delimiting the start of trailers.
Reported-by: Matthias Buehlmann <Matthias.Buehlmann@mabulous.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
t/t7513-interpret-trailers.sh | 23 +++++++++++++++++++++++
trailer.c | 2 +-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index 6602790b5f..af602ff329 100755
--- a/t/t7513-interpret-trailers.sh
+++ b/t/t7513-interpret-trailers.sh
@@ -1476,4 +1476,27 @@ test_expect_success 'suppress --- handling' '
test_cmp expected actual
'
+test_expect_success 'handling of empty continuations lines' '
+ tr _ " " >input <<-\EOF &&
+ subject
+
+ body
+
+ trailer: single
+ multi: one
+ _two
+ multi: one
+ _
+ _two
+ _three
+ EOF
+ cat >expect <<-\EOF &&
+ trailer: single
+ multi: one two
+ multi: one two three
+ EOF
+ git interpret-trailers --parse <input >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/trailer.c b/trailer.c
index 249ed618ed..7ca7200aec 100644
--- a/trailer.c
+++ b/trailer.c
@@ -846,7 +846,7 @@ static size_t find_trailer_start(const char *buf, size_t len)
possible_continuation_lines = 0;
continue;
}
- if (is_blank_line(bol)) {
+ if (is_blank_line(bol) && *bol == '\n') {
if (only_spaces)
continue;
non_trailer_lines += possible_continuation_lines;
--
2.30.0.667.g81c0cbc6fd
next prev parent reply other threads:[~2021-02-16 18:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-15 21:54 Bug Report: Multi-line trailers containing empty lines break parsing Matthias Buehlmann
2021-02-16 2:29 ` Junio C Hamano
2021-02-16 18:07 ` Taylor Blau [this message]
2021-02-16 19:39 ` Junio C Hamano
2021-02-16 19:47 ` Taylor Blau
2021-03-23 15:17 ` Christian Couder
2021-03-23 17:39 ` Junio C Hamano
2021-03-25 7:53 ` Christian Couder
2021-03-25 9:33 ` ZheNing Hu
2021-03-25 18:16 ` Junio C Hamano
2021-03-26 10:25 ` ZheNing Hu
2021-03-25 18:08 ` 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=YCwJ8tORQg2Air4r@nand.local \
--to=me@ttaylorr.com \
--cc=Matthias.Buehlmann@mabulous.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonathantanmy@google.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).