Bug 117968 - kbabel crashes whenever i try to open file
Summary: kbabel crashes whenever i try to open file
Status: RESOLVED FIXED
Alias: None
Product: kbabel
Classification: Miscellaneous
Component: KBabel editor (show other bugs)
Version: 1.10.2
Platform: Debian testing Linux
: NOR crash
Target Milestone: ---
Assignee: Stanislav Visnovsky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-09 00:36 UTC by uwe maysara
Modified: 2006-02-07 22:06 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
This file crashes kbabel (8.19 KB, text/plain)
2005-12-09 00:38 UTC, uwe maysara
Details

Note You need to log in before you can comment on or make changes to this bug.
Description uwe maysara 2005-12-09 00:36:31 UTC
Version:           1.10.2 (using KDE KDE 3.4.2)
Installed from:    Debian testing/unstable Packages
OS:                Linux

a file keeps crashing kbabel, i can open the file in vi but im not sure its the whole thing, someone suggested that some character freak kbabel out and it keeps reading for the infinity or something similar, i couldnt attach the file, it also crashed nautulis for the guy, he was using : KBabel 1.10 (Using KDE 3.4.0-6 RedHat) on kernel 2.6.13-1.1526_FC4smp (Fedora Core 4) and it exits with SIGSEGV, i use the things i filled out earlier.

hope this helps.
Comment 1 uwe maysara 2005-12-09 00:38:32 UTC
Created attachment 13830 [details]
This file crashes kbabel
Comment 2 Nicolas Goutte 2005-12-10 18:40:00 UTC
The PO file is invalid , as it has a "daily" on line 27. If it was supposed to be a comment, add a # and a space before it: 
# daily

Probably you are going to tell me that you have entered this comment in KBabel's comment editor. This is a bug that has been fixed in the meanwhile. (KBabel saves PO files while taking care that comments are starting with #)

For the bug itself, I leave it open, as KBabel should not crash when trying to load a bad file but should refuse to load with a message error.

Have a nice day!
Comment 3 Andras VOROSKOI 2006-01-10 20:53:17 UTC
Could you tell me how i can find out what's the problem with my .po file, because i've got the same error and i can't fix the file.
Comment 4 Nicolas Goutte 2006-01-16 09:30:47 UTC
On Tuesday 10 January 2006 20:53, Andras VOROSKOI wrote:
(...)
> Could you tell me how i can find out what's the problem with my .po
> file, because i've got the same error and i can't fix the file.


Using:

msgfmt -o /dev/null --check file.po

is mostly the easiest way.


If it gets too many unrelated errors, you can restrict the check to the 
header:
msgfmt -o /dev/null --check-header file.po
Major syntax errors (like "unknown keyword") should be caught in both cases.

As for fixing it, you need a text editor, like Kate. Of course, you can look 
directly with an editor and search the problem, but that is more tedious.

Have a nice day!
Comment 5 Andras VOROSKOI 2006-01-16 11:53:33 UTC
Thanks for your reply!

Well, then i've got some other error, because:

voroskoi@kavics:~$ msgfmt -vo /dev/null --check weechat/hu.po
142 translated messages, 798 untranslated messages.
voroskoi@kavics:~$ msgfmt -vo /dev/null --check-header weechat/hu.po
142 translated messages, 798 untranslated messages.

You can find the file here: http://frugalware.org/~voroskoi/hu.po

If you've got any idea let me know! Thanks in advance!
Comment 6 Andras VOROSKOI 2006-01-16 12:00:38 UTC
Sry, i've forgot to add that i'm using KDE 3.5.0, Kbabel 1.11 and i've installed them from Frugalware packages.
If you're intrested in compiling/configuring options i can also send them in.
Comment 7 Nicolas Goutte 2006-01-16 12:31:12 UTC
On Monday 16 January 2006 11:53, Andras VOROSKOI wrote:
(...)
> Well, then i've got some other error, because:


Please create another bug report. (Give the number of this bug report and you 
can also attach the file to the bug once it is created.)

>
> voroskoi kavics:~$ msgfmt -vo /dev/null --check weechat/hu.po
> 142 translated messages, 798 untranslated messages.
> voroskoi kavics:~$ msgfmt -vo /dev/null --check-header weechat/hu.po
> 142 translated messages, 798 untranslated messages.
>


> You can find the file here: http://frugalware.org/~voroskoi/hu.po


I have checked the file but I cannot find anything at first glance. Perhaps it 
is related to bug #120200 but perhaps not. That is why I would prefer that 
you create a new bug report.

>
> If you've got any idea let me know! Thanks in advance!


Have a nice day!
Comment 8 Nicolas Goutte 2006-02-06 14:03:12 UTC
SVN commit 506289 by goutte:

- fix isFuzzy function in catalog item
- assume a parse error if the catalog gets no entry from the import filter
  (KBabel cannot handle files without any entry; Fixes crash of bug #117968)
- try to improve handling of recoverd parse error, especially in the header
  (We cannot consider the parse error being recoverable on one side and
  on the other refuse to continue to process the file.)

CCBUG:117968
(I am not closing the bug, as I would like to understand why only the
catalog can decide that it is a parse error and why the import filter
cannot find by itself that it cannot do anything good with the test file.)


 M  +12 -1     common/catalog.cpp  
 M  +1 -1      common/catalogitem.cpp  
 M  +70 -41    filters/gettext/gettextimport.cpp  


--- branches/KDE/3.5/kdesdk/kbabel/common/catalog.cpp #506288:506289
@@ -940,10 +940,21 @@
 
 	if( error == OK || error == RECOVERED_PARSE_ERROR || error == HEADER_ERROR )
 	{
+            const uint entries = numberOfEntries();
+
+            if ( !entries )
+            {
+                // KBabel cannot work correctly with not any entry
+                kdWarning() << k_funcinfo << " No entries! Assuming parse error!" << endl;
+                delete filter;
+                return PARSE_ERROR;
+            }
+            
+            kdDebug( KBABEL ) << k_funcinfo << " Success (full or partial) " << entries << endl;
 	    setModified(false);
 	    d->_url=url;
 
-	    if( package.isNull() )
+            if( package.isEmpty() )
 	    {
 		d->_packageName=QString::null;
 		d->_packageDir=QString::null;
--- branches/KDE/3.5/kdesdk/kbabel/common/catalogitem.cpp #506288:506289
@@ -207,7 +207,7 @@
 
 bool CatalogItem::isFuzzy() const
 {
-    return d->_comment.find( QRegExp(",\\s*fuzzy") ) == -1;
+    return d->_comment.find( QRegExp(",\\s*fuzzy") ) != -1;
 }
 
 bool CatalogItem::isCformat() const
--- branches/KDE/3.5/kdesdk/kbabel/filters/gettext/gettextimport.cpp #506288:506289
@@ -3,10 +3,9 @@
 /* ****************************************************************************
   This file is part of KBabel
 
-  Copyright (C) 1999-2000 by Matthias Kiefer
-                            <matthias.kiefer@gmx.de>
-		2001-2003 by Stanislav Visnovsky
-			    <visnovsky@kde.org>
+  Copyright (C) 1999-2000 by Matthias Kiefer <matthias.kiefer@gmx.de>
+		2001-2003 by Stanislav Visnovsky <visnovsky@kde.org>
+  Copyright (C) 2006 by Nicolas GOUTTE <nicolasg@snafu.de>
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -60,6 +59,8 @@
 
 ConversionStatus GettextImportPlugin::load(const QString& filename, const QString&)
 {
+   kdDebug( KBABEL ) << k_funcinfo << endl;
+   
    if ( filename.isEmpty() ) {
       kdDebug(KBABEL) << "fatal error: empty filename to open" << endl;
       return NO_FILE;
@@ -75,10 +76,6 @@
 
    QFile file(filename);
 
-
-   bool recoveredError=false;
-   bool docbookFile=false;
-   	
    if ( !file.open( IO_ReadOnly ) )
       return NO_PERMISSIONS;
    
@@ -93,6 +90,8 @@
    QTextCodec* codec=codecForArray( ba, &hadCodec );
    
    QTextStream stream(ba,IO_ReadOnly);
+
+   // ### FIXME: if we have not get any codec, we should try UTF-8 as fallback.
    if(codec)
       stream.setCodec(codec);
    QIODevice *dev = stream.device();
@@ -106,17 +105,28 @@
    kdDebug(KBABEL) << "start parsing..." << endl;
 
    // first read header
-   ConversionStatus status = readHeader(stream);
+   const ConversionStatus status = readHeader(stream);
 
-   if(status!=OK)
+   bool recoveredErrorInHeader;
+
+   if ( status == OK )
    {
+      recoveredErrorInHeader = false;
+   }
+   else if ( status == RECOVERED_PARSE_ERROR )
+   {
+      kdDebug( KBABEL ) << "Recovered error in header entry" << endl;
+      recoveredErrorInHeader = true;
+   }
+   else
+   {
       emit signalClearProgressBar();
 
-      if( status == RECOVERED_PARSE_ERROR ) status = HEADER_ERROR;
-
+      kdDebug( KBABEL ) << "Parse error in header entry" << endl;
       return status;
    }
 
+   // ### TODO: check that the msgid is empty (if not, we might have a PO file without header)
    tempHeader.setMsgid( _msgid );
    tempHeader.setMsgstr( _msgstr );
    tempHeader.setComment( _comment );
@@ -129,11 +139,12 @@
    const bool docbookContent = (tempHeader.msgstr().find("application/x-xml2pot") != tempHeader.msgstr().end());
 
    // now parse the rest of the file
-   ConversionStatus success=OK;
    uint counter=0;
    QValueList<uint> errorIndex;
+   bool recoveredError=false;
+   bool docbookFile=false;
 
-   while(!stream.eof() && success==OK )
+   while( !stream.eof() )
    {
       kapp->processEvents(10);
       if( isStopped() )
@@ -141,13 +152,12 @@
          return STOPPED;
       }
 
-      success=readEntry(stream);
+      const ConversionStatus success=readEntry(stream);
 
       if(success==OK)
       {
          if( _obsolete )
          {
-               success=OK;
                tempObsolete.append(_comment);
          }
          else
@@ -168,7 +178,7 @@
       }
       else if(success==RECOVERED_PARSE_ERROR)
       {
-         success=OK;
+         kdDebug( KBABEL ) << "Recovered parse error in entry: " << counter << endl;
          recoveredError=true;
          errorIndex.append(counter);
          
@@ -182,6 +192,16 @@
          // add new entry to the list of entries
          appendCatalogItem(tempCatItem);
       }
+      else if ( success == PARSE_ERROR )
+      {
+         kdDebug( KBABEL ) << "Parse error in entry: " << counter << endl;
+         return PARSE_ERROR;
+      }
+      else
+      {
+         kdWarning( KBABEL ) << "Unknown success status, assumig parse error " << success << endl;
+         return PARSE_ERROR;
+      }
       counter++;
 
       const uint newPercent = (100*dev->at())/fileSize;
@@ -199,38 +219,47 @@
 
    emit signalClearProgressBar();
 
-   kdDebug(KBABEL) << "ready." << endl;
-      
-      if(counter==0)
-      {
-        // no items read
-	return PARSE_ERROR;
-      }
 
-   if(success!=PARSE_ERROR)
+   // ### TODO: can we check that there is no useful entry?
+   if ( !counter )
    {
-      setGeneratedFromDocbook(docbookContent || docbookFile);
+      // Empty file? (Otherwise, there would be a try of getting an entry and the count would be 1 !)
+      kdDebug( KBABEL ) << k_funcinfo << " Empty file?" << endl;
+      return PARSE_ERROR;
+   }
 
-      setHeader(tempHeader);
-      setCatalogExtraData(tempObsolete);
-      setErrorIndex(errorIndex);
+   kdDebug(KBABEL) << k_funcinfo << " ready" << endl;
 
-      if(hadCodec)
-         setFileCodec(codec);
-      else
-         setFileCodec(0);
+   // We have succesfully loaded the file (perhaps with recovered errors)
+   
+   setGeneratedFromDocbook(docbookContent || docbookFile);
+
+   setHeader(tempHeader);
+   setCatalogExtraData(tempObsolete);
+   setErrorIndex(errorIndex);
+
+   if(hadCodec)
+      setFileCodec(codec);
+   else
+      setFileCodec(0);
+   
+   setMimeTypes( "application/x-gettext" );
+
+   if ( recoveredErrorInHeader )
+   {
+      kdDebug( KBABEL ) << k_funcinfo << " Returning: header error" << endl;
+      return HEADER_ERROR;
    }
+   else if ( recoveredError )
+   {
+      kdDebug( KBABEL ) << k_funcinfo << " Returning: recovered parse error" << endl;
+      return RECOVERED_PARSE_ERROR;
+   }
    else
    {
-      return PARSE_ERROR;
+      kdDebug( KBABEL ) << k_funcinfo << " Returning: OK! :-)" << endl;
+      return OK;
    }
-   
-   setMimeTypes( "application/x-gettext" );
-
-   if(recoveredError)
-   	return RECOVERED_PARSE_ERROR;
-
-   return OK;
 }
 
 QTextCodec* GettextImportPlugin::codecForArray(QByteArray& array, bool* hadCodec)
Comment 9 Nicolas Goutte 2006-02-07 22:06:39 UTC
SVN commit 506906 by goutte:

Fix loading of PO files with recoverable errors in header:
- fix error messages displayed after opening the file.
  (A same error variable cannot be at the same time on one side HEADER_ERROR
  and on the other either OK or RECOVERED_ERROR).
- use KMessagebox::sorry for recovered errors
- rename the error HEADER_ERROR to RECOVERED_HEADER_ERROR
  (old name kept for source compatibility)
- return the new error NO_ENTRY_ERROR if the load does not result with at
  least one entry.
- opening a template needs to be similar than loading a file
  (except that recovered errors are not accepted)
- at level of the import plugin baic class, recognize RECOVERED_HEADER_ERROR
  as an positive state
BUG:117968
(This fixes the bug #117968. The extra data is considered now to be
a RECOVERED_HEADER_ERROR.)


 M  +22 -10    common/catalog.cpp  
 M  +19 -12    common/catalogfileplugin.h  
 M  +1 -1      common/importplugin.cpp  
 M  +7 -2      filters/gettext/gettextimport.cpp  
 M  +30 -49    kbabel/kbabelview.cpp