openbabel / openbabel

Open Babel is a chemical toolbox designed to speak the many languages of chemical data.
http://openbabel.org/
GNU General Public License v2.0
1.03k stars 403 forks source link

Reading InChI in Python terminates program #2128

Open Midnighter opened 4 years ago

Midnighter commented 4 years ago

Environment Information

conda info

     active environment : mnx
    active env location : ~/.local/share/miniconda3/envs/mnx
            shell level : 1
       user config file : ~/.condarc
 populated config files : ~/.condarc
          conda version : 4.8.2
    conda-build version : 3.18.11
         python version : 3.7.3.final.0
       virtual packages : __glibc=2.27
       base environment : ~/.local/share/miniconda3  (writable)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://conda.anaconda.org/bioconda/linux-64
                          https://conda.anaconda.org/bioconda/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : ~/.local/share/miniconda3/pkgs
                          ~/.conda/pkgs
       envs directories : ~/.local/share/miniconda3/envs
                          ~/.conda/envs
               platform : linux-64
             user-agent : conda/4.8.2 requests/2.22.0 CPython/3.7.3 Linux/5.3.0-7625-generic ubuntu/18.04 glibc/2.27
             netrc file : None
           offline mode : False

Open Babel version 3.0.0

Expected Behavior

I want to parse an InChI string to a pybel.Molecule. I can understand that this may fail but I believe it should be handled more transparently rather than terminating my program.

Actual Behavior

When I run below code, I get the following error.

terminate called after throwing an instance of 'std::logic_error'   
  what():  basic_string::_M_construct null not valid

Steps to Reproduce

from openbabel import pybel

molecule = pybel.readstring(
    "inchi",
    "InChI=1S/C26H37N7O19P3S/c1-26(2,20(37)23(38)29-6-5-15(34)28-7-8-56-25(39)13-3-4-16(35)49-13)10-48-55(45,46)52-54(43,44)47-9-14-19(51-53(40,41)42)18(36)24(50-14)33-12-32-17-21(27)30-11-31-22(17)33/h3-4,11-12,14,18-20,24,36-37H,5-10H2,1-2H3,(H,28,34)(H,29,38)(H,43,44)(H,45,46)(H2,27,30,31)(H2,40,41,42)/t14-,18?,19?,20-,24-/m0/s1/CRV:16.5",
)
baoilleach commented 4 years ago

As you say, it definitely shouldn't terminate in this way. This is characteristic of a segfault.