Bug 279809 - KMail2 crash on viewing mail in gb2312 encoding, edit to UTF-8 fixes it
Summary: KMail2 crash on viewing mail in gb2312 encoding, edit to UTF-8 fixes it
Status: RESOLVED FIXED
Alias: None
Product: kmail2
Classification: Applications
Component: general (show other bugs)
Version: 2.1.1
Platform: FreeBSD Ports FreeBSD
: NOR crash
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-10 12:15 UTC by Oliver
Modified: 2011-09-27 07:11 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.7.2


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver 2011-08-10 12:15:55 UTC
Version:           2.1.1 (using KDE 4.6.5) 
OS:                FreeBSD

A mail claiming to have gb2312 encoding (but almost exclusively English text) crashes KMail2 upon viewing that mail.

Reproducible: Always

Steps to Reproduce:
- Create new textfile
- Name it crashtest.msg
- Fill with the following:

Return-path: <person@somechinesecompany.example.org>
Envelope-to: me@mypersonaldomain.example.org
Delivery-date: Wed, 10 Aug 2011 03:44:48 +0200
Received: from [621.397.520.573] (helo=somemx.somechinesecompany.example.org)
From: <person@somechinesecompany.example.org>
Reply-To: person@somechinesecompany.example.org
To: me@mypersonaldomain.example.org
Date: Wed,10 aug 2011 09:37:29 +0800
X-Mailer: SMail
MIME-Version: 1.0
Content-Type: text/html;
     charset="gb2312"
Content-Transfer-Encoding: quoted-printable
Message-ID: <123456789@person@somechinesecompany.example.org>
Subject: Foo

bar

- Save textfile
- Open with KMail2 ( or from context-menu in Dolphin)

To fix the problem:
- Open message with your favorite text-editor
- change header like so:
     charset="UTF-8"


Actual Results:  
Application: KMail (kmail), signal: Segmentation fault: 11

Expected Results:  
No crash

The mail I received displayed this problem and the text I slammed together under 'steps to reproduce' also exhibits this problem
Comment 1 Laurent Montel 2011-08-17 21:32:31 UTC
backtrace ?
Comment 2 Laurent Montel 2011-08-17 21:34:55 UTC
I try your method but works fine here no crash.
Comment 3 Oliver 2011-08-17 22:02:17 UTC
I'm afraid the backtrace won't be of much help. I'll try to get kdepim to rebuild with debugging. This one is without:

http://heesakkers.info/showandtell/kmail-20110817-235648.kcrash.txt
Comment 4 Laurent Montel 2011-08-17 22:04:38 UTC
Thanks.
Perhaps you can forward email in private if possible.
Perhaps I will able to reproduce it.
Comment 5 Oliver 2011-08-17 22:39:52 UTC
The debugging rebuild was surprisingly simple:
http://heesakkers.info/showandtell/kmail-20110818-003415.kcrash.txt
Comment 6 Christophe Marin 2011-08-28 23:22:54 UTC
pasting inline: 
Thread 3 (Thread 80fc041c0 (LWP 100481/kmail)):
[KCrash Handler]
#7  0x0000000802ea9717 in KMime::Content::decodedText () from /usr/local/kde4/lib/libkmime.so.5
#8  0x0000000808d4bea9 in MessageViewer::ObjectTreeParser::processTextHtmlSubtype () from /usr/local/kde4/lib/libmessageviewer.so.5
#9  0x0000000808cfde22 in (anonymous namespace)::TextHtmlBodyPartFormatter::process () from /usr/local/kde4/lib/libmessageviewer.so.5
#10 0x0000000808d5c648 in MessageViewer::ObjectTreeParser::parseObjectTreeInternal () from /usr/local/kde4/lib/libmessageviewer.so.5
#11 0x0000000808d8cb2e in MessageViewer::ViewerPrivate::parseContent () from /usr/local/kde4/lib/libmessageviewer.so.5
#12 0x0000000808d8e12b in MessageViewer::ViewerPrivate::displayMessage () from /usr/local/kde4/lib/libmessageviewer.so.5
#13 0x0000000808d90196 in MessageViewer::ViewerPrivate::updateReaderWin () from /usr/local/kde4/lib/libmessageviewer.so.5
#14 0x0000000808da1e3d in MessageViewer::ViewerPrivate::qt_metacall () from /usr/local/kde4/lib/libmessageviewer.so.5
#15 0x00000008049f877a in QMetaObject::activate () from /usr/local/lib/qt4/libQtCore.so.4
Comment 7 Laurent Montel 2011-08-29 07:27:34 UTC
Christophe do you success to reproduce it ?
Comment 8 Christophe Marin 2011-08-29 12:39:08 UTC
no, maybe a real message using chinese symbols would help.
Comment 9 Axel Gonzalez 2011-09-26 19:41:40 UTC
I tested this with kdepim-4.7.1 and kdepimlibs-4.7.1 so YMMV

The problem is a NULL pointer reference in Content::decodedText() , kmime/kmime_content.cpp

This patch fixes it. The code is borrowed from Content::fromUnicodeString().

--- kmime/kmime_content.cpp.orig        2011-09-26 13:33:53.000000000 -0500
+++ kmime/kmime_content.cpp     2011-09-26 14:35:15.000000000 -0500
@@ -408,6 +408,12 @@
   QTextCodec *codec =
     KGlobal::charsets()->codecForName( QLatin1String( contentType()->charset() ), ok );
 
+  if ( !ok  || codec == NULL ) { // no suitable codec found => try local settings and hope the best ;-)
+    codec = KGlobal::locale()->codecForEncoding();
+    QByteArray chset = KGlobal::locale()->encoding();
+    contentType()->setCharset( chset );
+  }
+
   QString s = codec->toUnicode( d_ptr->body.data(), d_ptr->body.length() );
 
   if ( trimText || removeTrailingNewlines ) {
Comment 10 Oliver 2011-09-26 20:05:04 UTC
Yes, patching kdepimlibs4 with this patch fixes the problem for me. Great work, thanks!
Comment 11 Laurent Montel 2011-09-27 07:09:29 UTC
Git commit 8fc508c5f90149f8b97e0f3560f81f92b2bea7ac by Montel Laurent.
Committed on 27/09/2011 at 09:08.
Pushed by mlaurent into branch 'master'.

Fix Bug 279809 - KMail2 crash on viewing mail in gb2312 encoding, edit to UTF-8 fixes it

Patch from Axel Gonzalez tested by Oliver
The code is borrowed from Content::fromUnicodeString().
FIXED-IN:4.7.2
BUG: 279809

M  +6    -1    kmime/kmime_content.cpp

http://commits.kde.org/kdepimlibs/8fc508c5f90149f8b97e0f3560f81f92b2bea7ac
Comment 12 Laurent Montel 2011-09-27 07:10:35 UTC
Git commit 027da4d98f9b9099a51db4e8091de425acbea0f9 by Montel Laurent.
Committed on 27/09/2011 at 09:08.
Pushed by mlaurent into branch 'KDE/4.7'.

Fix Bug 279809 - KMail2 crash on viewing mail in gb2312 encoding, edit to UTF-8 fixes it

Patch from Axel Gonzalez tested by Oliver
The code is borrowed from Content::fromUnicodeString().
FIXED-IN:4.7.2
BUG: 279809
(cherry picked from commit 8fc508c5f90149f8b97e0f3560f81f92b2bea7ac)

M  +6    -1    kmime/kmime_content.cpp

http://commits.kde.org/kdepimlibs/027da4d98f9b9099a51db4e8091de425acbea0f9
Comment 13 Laurent Montel 2011-09-27 07:11:03 UTC
Ok thanks for this patch.
I applied to 4.7.2/master.
Regards