All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>,
	Git Mailing List <git@vger.kernel.org>
Cc: Don Zickus <dzickus@redhat.com>
Subject: mailinfo: don't require "text" mime type for attachments
Date: Sun, 30 Sep 2012 15:10:48 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.2.02.1209301458540.11079@i5.linux-foundation.org> (raw)


Currently "git am" does insane things if the mbox it is given contains 
attachments with a MIME type that aren't "text/*".

In particular, it will still decode them, and pass them "one line at a 
time" to the mail body filter, but because it has determined that they 
aren't text (without actually looking at the contents, just at the mime 
type) the "line" will be the encoding line (eg 'base64') rather than a 
line of *content*.

Which then will cause the text filtering to fail, because we won't 
correctly notice when the attachment text switches from the commit message 
to the actual patch. Resulting in a patch failure, even if patch may be a 
perfectly well-formed attachment, it's just that the message type may be 
(for example) "application/octet-stream" instead of "text/plain".

Just remove all the bogus games with the message_type. The only difference 
that code creates is how the data is passed to the filter function 
(chunked per-pred-code line or per post-decode line), and that difference 
is *wrong*, since chunking things per pre-decode line can never be a 
sensible operation, and cannot possibly matter for binary data anyway.

This code goes all the way back to March of 2007, in commit 87ab79923463 
("builtin-mailinfo.c infrastrcture changes"), and apparently Don used to 
pass random mbox contents to git. However, the pre-decode vs post-decode 
logic really shouldn't matter even for that case, and more importantly, "I 
fed git am crap" is not a valid reason to break *real* patch attachments.

If somebody really cares, and determines that some attachment is binary 
data (by looking at the data, not the MIME-type), the whole attachment 
should be dismissed, rather than fed in random-sized chunks to 
"handle_filter()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Don Zickus <dzickus@redhat.com>
---
 builtin/mailinfo.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index 2b3f4d955eaa..da231400b327 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -19,9 +19,6 @@ static struct strbuf email = STRBUF_INIT;
 static enum  {
 	TE_DONTCARE, TE_QP, TE_BASE64
 } transfer_encoding;
-static enum  {
-	TYPE_TEXT, TYPE_OTHER
-} message_type;
 
 static struct strbuf charset = STRBUF_INIT;
 static int patch_lines;
@@ -184,8 +181,6 @@ static void handle_content_type(struct strbuf *line)
 	struct strbuf *boundary = xmalloc(sizeof(struct strbuf));
 	strbuf_init(boundary, line->len);
 
-	if (!strcasestr(line->buf, "text/"))
-		 message_type = TYPE_OTHER;
 	if (slurp_attr(line->buf, "boundary=", boundary)) {
 		strbuf_insert(boundary, 0, "--", 2);
 		if (++content_top > &content[MAX_BOUNDARIES]) {
@@ -657,7 +652,6 @@ again:
 	/* set some defaults */
 	transfer_encoding = TE_DONTCARE;
 	strbuf_reset(&charset);
-	message_type = TYPE_TEXT;
 
 	/* slurp in this section's info */
 	while (read_one_header_line(&line, fin))
@@ -871,11 +865,6 @@ static void handle_body(void)
 			strbuf_insert(&line, 0, prev.buf, prev.len);
 			strbuf_reset(&prev);
 
-			/* binary data most likely doesn't have newlines */
-			if (message_type != TYPE_TEXT) {
-				handle_filter(&line);
-				break;
-			}
 			/*
 			 * This is a decoded line that may contain
 			 * multiple new lines.  Pass only one chunk

             reply	other threads:[~2012-09-30 22:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-30 22:10 Linus Torvalds [this message]
2012-10-01 13:27 ` mailinfo: don't require "text" mime type for attachments Don Zickus

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=alpine.LFD.2.02.1209301458540.11079@i5.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=dzickus@redhat.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.