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

Re: Bug Report: Multi-line trailers containing empty lines break parsing

From
Taylor Blau <me@ttaylorr.com>
Date
Feb 16, 2021, 18:07 UTC
Message-ID
<YCwJ8tORQg2Air4r@nand.local>
In-Reply-To
<xmqqczx0sq1o.fsf@gitster.c.googlers.com>
On Mon, Feb 15, 2021 at 06:29:55PM -0800, Junio C Hamano wrote:
Show 6 quoted lines
> 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
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 12 in “Bug Report: Multi-line trailers containing empty lines break parsing”
  1. Matthias BuehlmannFeb 15, 2021
  2. Junio C HamanoFeb 16, 2021
  3. Taylor BlauFeb 16, 2021
  4. Junio C HamanoFeb 16, 2021
  5. Taylor BlauFeb 16, 2021
  6. Christian CouderMar 23, 2021
  7. Junio C HamanoMar 23, 2021
  8. Christian CouderMar 25, 2021
  9. ZheNing HuMar 25, 2021
  10. Junio C HamanoMar 25, 2021
  11. ZheNing HuMar 26, 2021
  12. Junio C HamanoMar 25, 2021

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.