# Is git am supposed to decode MIME?

4 messages from 2017-10-04 to 2017-10-12. Participants: Florian Weimer, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/46899

## Florian Weimer, 2017-10-04 08:44

Subject: Is git am supposed to decode MIME?
Message-ID: <24940e12-3f72-1ef0-0983-58523d8dec51@redhat.com>
URL: https://gitlist.dev/e/24940e12-3f72-1ef0-0983-58523d8dec51%40redhat.com

```
The git am documentation talks about “mailboxes”.  I suppose these 
contain messages in Internet Mail syntax.  Is git am supposed to decode 
MIME?

I'm asking because I have a message whose body is encoded as 
quoted-printable, but git am does not parse the patch contained in it.

If git am is supposed to deal with this, I'll dig deeper and try to 
figure out where things go wrong.

Thanks,
Florian

```

## Jeff King, 2017-10-04 09:25

Subject: Re: Is git am supposed to decode MIME?
Message-ID: <20171004092546.vnjddxqwvia5cfn6@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20171004092546.vnjddxqwvia5cfn6%40sigill.intra.peff.net
In-Reply-To: <24940e12-3f72-1ef0-0983-58523d8dec51@redhat.com>

```
On Wed, Oct 04, 2017 at 10:44:31AM +0200, Florian Weimer wrote:

> The git am documentation talks about “mailboxes”.  I suppose these contain
> messages in Internet Mail syntax.  Is git am supposed to decode MIME?
> 
> I'm asking because I have a message whose body is encoded as
> quoted-printable, but git am does not parse the patch contained in it.
> 
> If git am is supposed to deal with this, I'll dig deeper and try to figure
> out where things go wrong.

Yes, it should. I just double-checked with the toy patch patch below,
and it correctly extracted the quoted-printable from the commit message
and patch, as well as in the headers.

-- >8 --
From peff@peff.net Wed Oct  4 05:21:57 2017
Date: Wed, 4 Oct 2017 05:21:55 -0400
From: =?utf-8?Q?=C3=81ccented N=C3=A1me?= <peff@peff.net>
To: Jeff King <peff@peff.net>
Subject: [PATCH] add 8bit content
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

This commit message also has s=C3=B3me 8-bit characters which
will need qp-encoding.

Signed-off-by: =C3=81ccented N=C3=A1me <peff@peff.net>
---
 file | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/file b/file
index d95f3ad..d39c7fc 100644
--- a/file
+++ b/file
@@ -1 +1 @@
-content
+8-bit c=C3=B3ntent
--=20
2.14.2.1117.g65a3442612


```

## Junio C Hamano, 2017-10-04 10:10

Subject: Re: Is git am supposed to decode MIME?
Message-ID: <xmqqzi979qbe.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqzi979qbe.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <24940e12-3f72-1ef0-0983-58523d8dec51@redhat.com>

```
Florian Weimer <fweimer@redhat.com> writes:

> The git am documentation talks about “mailboxes”.  I suppose these
> contain messages in Internet Mail syntax.  Is git am supposed to
> decode MIME?
>
> I'm asking because I have a message whose body is encoded as
> quoted-printable, but git am does not parse the patch contained in it.
>
> If git am is supposed to deal with this, I'll dig deeper and try to
> figure out where things go wrong.

The code to check should be in <mailinfo.c>.  As its comment says,
the code was not designed to be a full MIME parser--we just have a
code that (empirically) works in practice on messages produced when
a patch is attached to a message via popular MUAs, not written from
the MIME RFC spec.

Thanks for your interest in making the world a better place ;-)
Very much appreciated.



```

## Florian Weimer, 2017-10-12 13:20

Subject: Re: Is git am supposed to decode MIME?
Message-ID: <39aebcbd-7820-eafe-3c44-b96b057d0059@redhat.com>
URL: https://gitlist.dev/e/39aebcbd-7820-eafe-3c44-b96b057d0059%40redhat.com
In-Reply-To: <20171004092546.vnjddxqwvia5cfn6@sigill.intra.peff.net>

```
On 10/04/2017 11:25 AM, Jeff King wrote:
> On Wed, Oct 04, 2017 at 10:44:31AM +0200, Florian Weimer wrote:
> 
>> The git am documentation talks about “mailboxes”.  I suppose these contain
>> messages in Internet Mail syntax.  Is git am supposed to decode MIME?
>>
>> I'm asking because I have a message whose body is encoded as
>> quoted-printable, but git am does not parse the patch contained in it.
>>
>> If git am is supposed to deal with this, I'll dig deeper and try to figure
>> out where things go wrong.
> 
> Yes, it should. I just double-checked with the toy patch patch below,
> and it correctly extracted the quoted-printable from the commit message
> and patch, as well as in the headers.

It took me a while, but I know think the message is simply corrupted. 
It's encoded with quoted-printable, and that looks correct, but it ends 
with:

@@ -5137,11 +5114,13 @@ __libc_mallopt (int param_number, int value)
    if (__malloc_initialized < 0)
      ptmalloc_init ();
    __libc_lock_lock (av->mutex);
-  /* Ensure initialization/consolidation */
-  malloc_consolidate (av);
=20
    LIBC_PROBE (memory_mallopt, 2, param_number, value);
=20
+  /* We must consolidate main arena before changing max_fast
+     (see definition of set_max_fast).  */
+  malloc_consolidate (av);
+
    switch (param_number)
      {
      case M_MXFAST:=

The “=” masks the final newline, and that doesn't decode into a valid 
diff hunk.  The file being patched continues after that, so it's not 
even the “\ No newline at end of file” case.

So in short, there is no Git bug here, and I just failed to interpret 
the “git am” diagnostics correctly:

Applying: Improve malloc initialization sequence
error: corrupt patch at line 342
Patch failed at 0001 Improve malloc initialization sequence
The copy of the patch that failed is found in: .git/rebase-apply/patch

Line 342 refers to the file in .git/rebase-apply/patch, not the original 
input, and it took me a while to figure that out.

Thanks,
Florian

```
