Menu

#679 Crash reading CML files

2.2.x
open
nobody
5
2012-10-23
2010-11-21
No

Program received signal SIGSEGV, Segmentation fault.
0xb55e11c7 in OpenBabel::XMLConversion::ReadStream(void, char, int) () from /usr/lib/openbabel/2.2.3/cmlformat.so
(gdb) bt

0 0xb55e11c7 in OpenBabel::XMLConversion::ReadStream(void, char, int) () from /usr/lib/openbabel/2.2.3/cmlformat.so

1 0xb5e959fc in xmlParserInputBufferGrow () from /usr/lib/libxml2.so.2

2 0xb5f1b7e0 in xmlTextReaderSetup () from /usr/lib/libxml2.so.2

3 0xb55e251c in OpenBabel::XMLConversion::GetDerived(OpenBabel::OBConversion*, bool) () from /usr/lib/openbabel/2.2.3/cmlformat.so

4 0xb55dbd02 in OpenBabel::XMLMoleculeFormat::ReadMolecule(OpenBabel::OBBase, OpenBabel::OBConversion) () from /usr/lib/openbabel/2.2.3/cmlformat.so

5 0xb7e9c011 in OpenBabel::OBConversion::Read(OpenBabel::OBBase, std::istream) () from /usr/lib/libopenbabel.so.3

6 0xb7e9c37e in OpenBabel::OBConversion::ReadFile(OpenBabel::OBBase*, std::string) () from /usr/lib/libopenbabel.so.3

7 0x0804d21e in MainWindow::MainWindow(QWidget*) ()

8 0x0804bcf5 in main (argc=1, argv=0xbffff564) at main.cpp:7

You can find my code including the cml-files here:
http://gitorious.org/molecules

Discussion

  • Carsten Niehaus

    Carsten Niehaus - 2010-11-21

    I just ran the app in Valgrind. I got this output:

    ==7186== Invalid read of size 4
    ==7186== at 0x4FB79EA: std::locale::~locale() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x4FB49E0: std::ios_base::~ios_base() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x4FCD872: std::basic_istream<char, std::char_traits<char=""> >::~basic_istream() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x40FC03A: OpenBabel::OBConversion::~OBConversion() (in /usr/lib/libopenbabel.so.3.0.3)
    ==7186== by 0x723B420: OpenBabel::XMLConversion::~XMLConversion() (in /usr/lib/openbabel/2.2.3/cmlformat.so)
    ==7186== by 0x40FBE27: OpenBabel::OBConversion::~OBConversion() (in /usr/lib/libopenbabel.so.3.0.3)
    ==7186== by 0x804D57D: MainWindow::MainWindow(QWidget) (in /home/carsten/git/Molecules/Molecules)
    ==7186== by 0x804BCF4: main (main.cpp:7)
    ==7186== Address 0x74c6524 is 116 bytes inside a block of size 280 free'd
    ==7186== at 0x4023881: operator delete(void
    ) (vg_replace_malloc.c:387)
    ==7186== by 0x4FCA0EF: std::basic_ifstream<char, std::char_traits<char=""> >::~basic_ifstream() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x40F738F: OpenBabel::OBConversion::ReadFile(OpenBabel::OBBase, std::string) (in /usr/lib/libopenbabel.so.3.0.3)
    ==7186== by 0x804D21D: MainWindow::MainWindow(QWidget
    ) (in /home/carsten/git/Molecules/Molecules)
    ==7186== by 0x804BCF4: main (main.cpp:7)
    ==7186==
    ==7186== Invalid read of size 4
    ==7186== at 0x4FB79FB: std::locale::~locale() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x4FB49E0: std::ios_base::~ios_base() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x4FCD872: std::basic_istream<char, std::char_traits<char=""> >::~basic_istream() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x40FC03A: OpenBabel::OBConversion::~OBConversion() (in /usr/lib/libopenbabel.so.3.0.3)
    ==7186== by 0x723B420: OpenBabel::XMLConversion::~XMLConversion() (in /usr/lib/openbabel/2.2.3/cmlformat.so)
    ==7186== by 0x40FBE27: OpenBabel::OBConversion::~OBConversion() (in /usr/lib/libopenbabel.so.3.0.3)
    ==7186== by 0x804D57D: MainWindow::MainWindow(QWidget) (in /home/carsten/git/Molecules/Molecules)
    ==7186== by 0x804BCF4: main (main.cpp:7)
    ==7186== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==7186==
    ==7186==
    ==7186== Process terminating with default action of signal 11 (SIGSEGV)
    ==7186== Access not within mapped region at address 0x0
    ==7186== at 0x4FB79FB: std::locale::~locale() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x4FB49E0: std::ios_base::~ios_base() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x4FCD872: std::basic_istream<char, std::char_traits<char=""> >::~basic_istream() (in /usr/lib/libstdc++.so.6.0.13)
    ==7186== by 0x40FC03A: OpenBabel::OBConversion::~OBConversion() (in /usr/lib/libopenbabel.so.3.0.3)
    ==7186== by 0x723B420: OpenBabel::XMLConversion::~XMLConversion() (in /usr/lib/openbabel/2.2.3/cmlformat.so)
    ==7186== by 0x40FBE27: OpenBabel::OBConversion::~OBConversion() (in /usr/lib/libopenbabel.so.3.0.3)
    ==7186== by 0x804D57D: MainWindow::MainWindow(QWidget
    ) (in /home/carsten/git/Molecules/Molecules)
    ==7186== by 0x804BCF4: main (main.cpp:7)

     
  • Noel O'Boyle

    Noel O'Boyle - 2010-11-24

    This bug is filed against 2.2.x. Can you check whether it works for 2.3.0?

     
  • Nobody/Anonymous

    Actually, I can't. I am using a Debian-Squeeze machine and there is no update available. Currently, I have no time to setup the full development environment, I am only using the deb-packages.... Perhaps later.

     
  • Noel O'Boyle

    Noel O'Boyle - 2010-11-25

    Well, in that case, can you provide a link to (or attach) a particular test file for which your code fails? I can at least check that ReadFile works for me with the latest code.

     
  • Carsten Niehaus

    Carsten Niehaus - 2010-11-25

    The 'funny' thing is that my code does the same thing with many files (a for-loop) and when I am running my code 10 times it crashes at different molecules each time. So perhaps it is a racecondition or something.

    My testfiles are taken from chem-file.sf.net (I copied them for testing):

    http://gitorious.org/molecules/molecules/trees/master/data

    My code is:

            bool fileworks = obconversion.ReadFile(&mol, fullFileName);
    

    if (fileworks){
    qDebug() << "Opened molecule " << mol.GetTitle();
    QString formula = QString::fromStdString( mol.GetFormula() );
    }

    See this link for reference:
    http://gitorious.org/molecules/molecules/blobs/master/mainwindow.cpp#line35

     
  • Carsten Niehaus

    Carsten Niehaus - 2010-12-12

    I was just able to run the code on a Fedora 14-setup (which is OpenBabel 2.2.3). I got this backtrace:

    Program received signal SIGSEGV, Segmentation fault.
    OpenBabel::XMLConversion::ReadStream (context=0x8214f60, buffer=0x8230b30 "", len=4) at xml.cpp:319
    319 if(!ifs->good() || ifs->eof())

    (gdb) bt

    0 OpenBabel::XMLConversion::ReadStream (context=0x8214f60, buffer=0x8230b30 "", len=4) at xml.cpp:319

    1 0x01c103f2 in xmlParserInputBufferGrow__internal_alias (in=0x821b578, len=4) at xmlIO.c:3156

    2 0x01c9c2d8 in xmlTextReaderSetup__internal_alias (reader=0x818f5e0, input=0x821b578, URL=0x1fb0d79 "", encoding=0x0, options=65536) at xmlreader.c:5005

    3 0x01faf0b9 in OpenBabel::XMLConversion::GetDerived (pConv=0xbffff1f8, ForReading=true) at xml.cpp:145

    4 0x01fadda8 in OpenBabel::XMLMoleculeFormat::ReadMolecule (this=0x219dc00, pOb=0xbffff0e0, pConv=0xbffff1f8) at ../../../include/openbabel/xml.h:232

    5 0x001cc5b3 in OpenBabel::OBConversion::Read (this=0xbffff1f8, pOb=0xbffff0e0, pin=0x821b708) at obconversion.cpp:745

    6 0x001cc94e in OpenBabel::OBConversion::ReadFile (this=0xbffff1f8, pOb=0xbffff0e0, filePath="./data/2-chloropropane.cml") at obconversion.cpp:922

    7 0x0804c4af in MainWindow::MainWindow (this=0xbffff2f0, parent=0x0) at mainwindow.cpp:33

    8 0x0804b5bc in main (argc=1, argv=0xbffff3d4) at main.cpp:7

    It seems the CML is also invalid as I also got this information:

    ==============================
    *** Open Babel Error in XML Parser ./data/2-bromophenol.cml
    Namespace default prefix was not found

    Opened molecule 2-Bromo-2-methylpropane
    Formula: "C4H9Br"
    "./data/2-bromopropane.cml"
    Opened molecule 2-Bromopropane
    Formula: "C3H7Br"
    "./data/2-chloro-2-methylpropane.cml"
    :1: namespace warning : Namespace default prefix was not found
    <formula concise=" C 4 H 9 Cl 1 "/>
    ^
    ==============================

    But even with invalid CML Openbabel shouldn't crash as I checked the files with ReadFile and got True back.

     
  • Carsten Niehaus

    Carsten Niehaus - 2010-12-12

    Ok, I just tested the SAME code with mol-files and it works. So the bug has to be in the CML-parsing.

    The complete diff is this:

    • obconversion.SetInFormat("cml");
    • obconversion.SetInFormat("mol");

      QDir directory("data");
      - QStringList filelist = directory.entryList( QStringList(".cml") );
      + QStringList filelist = directory.entryList( QStringList("
      .mol") );