Bug 114535

Summary: Using jis7 encoding causes the entire Konsole to freeze.
Product: [Applications] konsole Reporter: David Capel <wot.narg>
Component: generalAssignee: Konsole Developer <konsole-devel>
Status: RESOLVED LATER    
Severity: normal CC: adaptee
Priority: NOR    
Version: 1.6.6   
Target Milestone: ---   
Platform: Debian testing   
OS: Linux   
Latest Commit: Version Fixed In:

Description David Capel 2005-10-16 22:47:33 UTC
Version:           1.5.2 and 1.6 at least (using KDE KDE 3.4.91)
Installed from:    Debian testing/unstable Packages
Compiler:          gcc 4.0 
OS:                Linux

Changing to the jis7 encoding in konsole causes it to freeze once you enter a command.


To reproduce:
1. Open Konsole.
2. Settings > Encoding > jis7
3. type something (anything :p)
4. KER-Freeze.

I'm using kde3.5b1 kubuntu debs, with konsole version 1.6, but the person who found it first (and wanted me to report it :p) is using konsole version 1.5.2 on kde 3.4.3. Others in the #kde channel on freenode could reproduce it also.
Comment 1 Kurt Hindenburg 2005-10-16 23:10:58 UTC
Yep, it freezes using 100% CPU.
Comment 2 Steven P. Ulrick 2005-10-24 23:55:43 UTC
Same here.  Only goes to about 92.5% CPU, though :)  My version of Konsole is 1.6 from SVN Branch 3.5.  All the rest of my KDE is compiled from Branch 3.5 as well.  Also, I am running Fedora Core 3.
Comment 3 Thiago Macieira 2005-10-25 02:58:38 UTC
Bug in the code, but I don't know whose fault it is.

297     void TEmulation::onRcvBlock(const char *s, int len)
298     {
299       emit notifySessionState(NOTIFYACTIVITY);
300
301       bulkStart();
302       for (int i = 0; i < len; i++)
303       {
304
305         QString result = decoder->toUnicode(&s[i],1);
306         int reslen = result.length();
307
308         // If we get a control code halfway a multi-byte sequence
309         // we flush the decoder and continue with the control code.
310         if ((s[i] < 32) && (s[i] > 0))
311         {
312            // Flush decoder
313            while(!result.length())
314               result = decoder->toUnicode(&s[i],1);
315            reslen = 1;
316            result.setLength(reslen);
317            result[0] = QChar(s[i]);
318         }

decoder is of type QJisDecoder.

The problem is that:
1) decoder is in state "esc"
2) decoder->toUnicode("\033",1) returns an empty QString
3) the loop in lines 313 and 314 is infinite if the decoder returns an empty string.

Maybe an increment on i was forgotten on the 313-314 loop?
Comment 4 Kurt Hindenburg 2005-11-13 07:44:53 UTC
SVN commit 480087 by hindenburg:

Remove jis7 from Encoding menu due to infinite loop.

CCBUG: 114535


 M  +3 -0      konsole.cpp  


--- branches/KDE/3.5/kdebase/konsole/konsole/konsole.cpp #480086:480087
@@ -632,6 +632,9 @@
       selectSetEncoding = new KSelectAction( i18n( "&Encoding" ), SmallIconSet( "charset" ), 0, this, SLOT(slotSetEncoding()), actions, "set_encoding" );
       QStringList list = KGlobal::charsets()->descriptiveEncodingNames();
       list.prepend( i18n( "Default" ) );
+
+      // BR114535 : Remove jis7 due to infinite loop.
+      list.remove( i18n( "Japanese ( jis7 )" ) );
       selectSetEncoding->setItems(list);
       selectSetEncoding->setCurrentItem (0);
       selectSetEncoding->plug(m_options);
Comment 5 Kurt Hindenburg 2005-11-13 11:45:46 UTC
SVN commit 480103 by hindenburg:

Let's handle the jis7 problem this way.  That way the translators don't have
any new strings and I don't have to worry about the loading/saving not working
again.  It is too bad it is not possible to disable an item in a KSelectAction.

CCBUG: 107329
CCBUG: 114535


 M  +8 -6      konsole.cpp  


--- branches/KDE/3.5/kdebase/konsole/konsole/konsole.cpp #480102:480103
@@ -632,11 +632,6 @@
       selectSetEncoding = new KSelectAction( i18n( "&Encoding" ), SmallIconSet( "charset" ), 0, this, SLOT(slotSetEncoding()), actions, "set_encoding" );
       QStringList list = KGlobal::charsets()->descriptiveEncodingNames();
       list.prepend( i18n( "Default" ) );
-
-      // BR114535 : Remove jis7 due to infinite loop.
-      // If you fix this issue and remove the line below,  remember to 
-      // remove the line in setSessionEncoding() (search for jis7).
-      list.remove( i18n( "Japanese ( jis7 )" ) );
       selectSetEncoding->setItems(list);
       selectSetEncoding->setCurrentItem (0);
       selectSetEncoding->plug(m_options);
@@ -863,6 +858,14 @@
     bool found;
     QString enc = KGlobal::charsets()->encodingForName(selectSetEncoding->currentText());
     qtc = KGlobal::charsets()->codecForName(enc, found);
+
+    // BR114535 : Remove jis7 due to infinite loop.
+    if ( enc == "jis7" ) {
+      kdWarning()<<"Encoding Japanese (jis7) currently does not work!  BR114535"<<endl;
+      qtc = QTextCodec::codecForLocale();
+      selectSetEncoding->setCurrentItem( 0 );
+    }
+
     if(!found)
     {
       kdWarning() << "Codec " << selectSetEncoding->currentText() << " not found!" << endl;
@@ -2631,7 +2634,6 @@
     }
 
     i++;                 // Take into account the first entry: Default
-    if ( i > 24 ) i--;   // Handle the removed jis7 entry
     //kdDebug()<<"setSessionEncoding="<<encoding<<"; "<<i<<endl;
 
     session->setEncodingNo( i );
Comment 6 Kurt Hindenburg 2006-05-12 18:41:31 UTC
Not a crash since user can't pick jis7.
Comment 7 Robert Knight 2007-07-19 20:11:28 UTC
After commenting-out the jis7 check in konsole.cpp in the latest KDE 3.5 branch with Qt 3.3.7 and KDE 3.5.6 libraries I was able to run Konsole and pick the jis7 encoding without problems.  Is there anyone here who could double-check this with similar Qt,KDE versions and report on whether the problem still exists?

Index: konsole.cpp
===================================================================
--- konsole.cpp (revision 611528)
+++ konsole.cpp (working copy)
@@ -869,12 +869,14 @@
     QString enc = KGlobal::charsets()->encodingForName(selectSetEncoding->currentText());
     qtc = KGlobal::charsets()->codecForName(enc, found);

+# if 0
     // BR114535 : Remove jis7 due to infinite loop.
     if ( enc == "jis7" ) {
       kdWarning()<<"Encoding Japanese (jis7) currently does not work!  BR114535"<<endl;
       qtc = QTextCodec::codecForLocale();
       selectSetEncoding->setCurrentItem( 0 );
     }
+#endif

     if(!found)
     {
Comment 8 Jekyll Wu 2011-07-26 21:22:21 UTC
This problem seems fixed in KDE4 konsole

Changing encoding to jis7 would not make konsole freeze when I start typing. 

I'm using konsole-2.7.999