[PATCH] base64 and CRLF spread over two lines

Dennis Preiser <[email protected]> Sun, 23 Aug 2015 10:33:06 +0200
Newsgroups gmane.network.tin.devel
Message-ID <[email protected]>
--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Hello,

in rfc2045.c:put_rest() we skip over CRLF only if they occur in the same
physical base64 encoded line (~270). If it is spread over two lines
(first line ends with '\r' and second line starts with '\n') the current
code leave it as it is.

The following article shows this issue:

| Newsgroups: de.alt.test,de.test
| Subject: Ignore - X-Prost🍻 und Fluppe²🚬...
| Followup-To: de.test
| Date: Sat, 22 Aug 2015 17:26:34 +0200
| Message-ID: <[email protected]>
| Mime-Version: 1.0
| Content-Type: text/plain; charset=UTF-8
| Content-Transfer-Encoding: base64

Here is the point where CRLF was spread over two lines:

| lDNcm3b2aX/op+nSmz9Z8pxbBsIDRcW/9Ir+FBNO02CFam4ED2PstijMJ6YSb8yS
| EOHbdOnyuYF6F8Pcf3in2CdHOSq34RFgDlrE8Ie9w6qXlEY4TfCBBQ5Fx461RAtS^M
| 8nId41i21S1pqHy6vtEesguhPGwYU+IFDcSZKWxoRPyZQZosZwGW1fF3u93CygC3

                                                                  ^^

Attached a possible fix for this issue.

Dennis

--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="2015-08-23.diff"

diff -urp tin-2.3.1_r6/src/rfc2045.c tin-2.3.1_r7/src/rfc2045.c
--- tin-2.3.1_r6/src/rfc2045.c	2014-12-24 09:41:24.000000000 +0100
+++ tin-2.3.1_r7/src/rfc2045.c	2015-08-23 10:10:17.000000000 +0200
@@ -283,6 +283,11 @@ put_rest(
 	}
 	if (c == '\n') {
 		/*
+		 * Look for CRLF spread over two lines.
+		 */
+		if (put_chars && (*line)[put_chars -1] == '\r')
+			--put_chars;
+		/*
 		 * FIXME: Adding a newline may be not correct. At least it may
 		 * be not what the author of that article intended.
 		 * Unfortunately, a newline is expected at the end of a line by

--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KdGluLWRldiBt
YWlsaW5nIGxpc3QKdGluLWRldkB0aW4ub3JnCmh0dHA6Ly9saXN0cy50aW4ub3JnL2NnaS1iaW4v
bWFpbG1hbi9saXN0aW5mby90aW4tZGV2Cg==

--2oS5YaxWCcQjTEyO--