Bug 362404

Summary: Crash with ISO 2022-JP Charset
Product: [Applications] konversation Reporter: Mikiya Okuno <mikiya.okuno>
Component: generalAssignee: Konversation Developers <konversation-devel>
Status: RESOLVED FIXED    
Severity: normal CC: hein, ottoteixeira
Priority: NOR    
Version: 1.6   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Mikiya Okuno 2016-04-28 10:32:15 UTC
Crash happens if ISO 2022-JP charset is set to one of IRC server. This is because KCharsets::codecForName() returns NULL for "ISO 2022-JP". To prevent this issue, charset name should be changed to "ISO-2022-JP", which has two hyphens instead of one space and one hyphen.

I filed bug #362401 for KCharsets problem. However, Konversation should also handle the situation when KCharsets::codecForName() returns NULL, in order to avoid crash.

Reproducible: Always

Steps to Reproduce:
1. Connect to server with Codec=ISO 2022-JP defined in konversationrc
2. See crash happens
3.

Actual Results:  
konversasion crashes.

Expected Results:  
It should report an error instead of crash.

Stacktrace

(gdb) bt
#0  QTextCodec::fromUnicode (this=0x0, str=...) at codecs/qtextcodec.cpp:806
#1  0x0000000000540285 in Server::generateJoinCommand (this=this@entry=0x1191220, tmpList=...) at /home/portage/portage/net-irc/konversation-1.6/work/konversation-1.6/src/irc/server.cpp:3804
#2  0x0000000000541213 in Server::updateAutoJoin (this=this@entry=0x1191220, channels=...) at /home/portage/portage/net-irc/konversation-1.6/work/konversation-1.6/src/irc/server.cpp:3775
#3  0x00000000005446c6 in Server::Server (this=0x1191220, parent=<optimized out>, settings=...) at /home/portage/portage/net-irc/konversation-1.6/work/konversation-1.6/src/irc/server.cpp:129
#4  0x0000000000516f8c in ConnectionManager::connectTo (this=this@entry=0xdb1540, flag=flag@entry=Konversation::CreateNewConnection, settings=...) at /home/portage/portage/net-irc/konversation-1.6/work/konversation-1.6/src/connectionmanager.cpp:155
#5  0x0000000000517470 in ConnectionManager::connectTo (this=0xdb1540, flag=flag@entry=Konversation::CreateNewConnection, serverGroupId=<optimized out>) at /home/portage/portage/net-irc/konversation-1.6/work/konversation-1.6/src/connectionmanager.cpp:95
#6  0x00000000004ef162 in Application::newInstance (this=this@entry=0x7fffffffc3c0, args=args@entry=0x7fffffffc350) at /home/portage/portage/net-irc/konversation-1.6/work/konversation-1.6/src/application.cpp:248
#7  0x00000000004cc531 in main (argc=1, argv=<optimized out>) at /home/portage/portage/net-irc/konversation-1.6/work/konversation-1.6/src/main.cpp:150

See "this" is NULL(0x0) at frame #0.
Comment 1 Mikiya Okuno 2016-04-28 10:40:46 UTC
Crash will happen if getCodec() returns null on the following code:

            uint currentLength = getIdentity()->getCodec()->fromUnicode(channel).length();

getCodec() returns NULL because m_codec is set to NULL in Identity::setCodecName().
Comment 2 Otto Teixeira 2016-04-29 01:36:35 UTC
In irccharsets.cpp:

Why this code?
if(shortName == QStringLiteral("ISO 2022-JP")) {
    return QTextCodec::codecForName( "jis7" );
}
That returns NULL.

This one:
return KCharsets::charsets()->codecForName( shortName.toLatin1() );

Seems to work fine for "Codec = ISO 2022-JP"
Comment 3 Eike Hein 2016-05-03 06:08:24 UTC
This is apparently ancient code from 2004 -- it appears QTextCodec::codecForLocale didn't return something sensible for ja_JP back then. I'm inclined to just drop all these hacks 10 years later.
Comment 4 Eike Hein 2016-05-03 06:51:02 UTC
codecForLocale() returns UTF-8 for jp_JP on my system, and I'm not up to speed on whether Japanese networks have modernized and stopped defaulting to jis7 these days, so let's keep it for now ...

KCharsets::codecForName() works with both "ISO 2022-JP" and "ISO-2022-JP" for me, but returns ISO-8859-1 for jis7, which is ... an interesting development. It means the jis7 option will actually crash currently.

I'm changing the jp_JP default from jis7 to ISO-2022-JP and mangling jis7 to ISO-2022-JP (i.e. the reverse of the quoted code), along with adding a fallback to UTF-8 in case of null codecs.