kylelutz / chemkit

A C++ library for molecular modelling, cheminformatics and molecular visualization.
http://www.chemkit.org
BSD 3-Clause "New" or "Revised" License
54 stars 26 forks source link

malformed SDF string causes segfault #27

Open itdaniher opened 12 years ago

itdaniher commented 12 years ago

import chemkit st = """ 2 1 0 0 0 0 999 V2000 ... -0.4125 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 ... 0.4125 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0""" f = chemkit.MoleculeFile() f.setFormat("sdf") True f.readString(st) Segmentation fault: 11

For your copying and pasting pleasure, the string above is:

' 2 1 0 0 0 0 999 V2000\n -0.4125 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.4125 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n'

kylelutz commented 12 years ago

Strange, I don't get a segfault when I run it. For me, the file is read successfully but only an empty molecule is returned. Could you run it under gdb and post the backtrace?

The main issue is that the file data doesn't start with the three comment lines. Prepending "\n\n\n" to the string resolves the issue and the ethane molecule is read correctly.

itdaniher commented 12 years ago

Interesting, when I run from the string I copied and pasted above, it does not segfault. That said, https://gist.github.com/2923979 does segfault repeatably, and from within gdb.

Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0xfffffffffffffff0 0x0000000102670246 in MdlFileFormat::readSdfFile ()