xtb icon indicating copy to clipboard operation
xtb copied to clipboard

Stack smashing for linear molecules

Open chem-william opened this issue 3 years ago • 5 comments

Describe the bug When running the following command:

xtb mol.mol --ohess

a crash will occur in the section "Thermodynamic Functions" with the following error:

*** stack smashing detected ***: xtb terminated

To Reproduce Steps to reproduce the behaviour: Optimize and calculate the hessian for the following molecule:


     RDKit          3D

 12 11  0  0  0  0  0  0  0  0999 V2000
   -0.6397    5.1995    3.0833 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.5134    4.1732    2.4743 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.3514    2.8563    1.6927 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.2251    1.8300    1.0836 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0631    0.5131    0.3021 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0631   -0.5131   -0.3069 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.2251   -1.8300   -1.0884 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.3514   -2.8563   -1.6974 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.5134   -4.1732   -2.4790 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.6397   -5.1995   -3.0881 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7517    6.1103    3.6238 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.7517   -6.1103   -3.6285 H   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  3  0
  2  3  1  0
  3  4  3  0
  4  5  1  0
  5  6  3  0
  6  7  1  0
  7  8  3  0
  8  9  1  0
  9 10  3  0
  1 11  1  0
 10 12  1  0
M  END

Expected behaviour I expected the program to terminate without an error.

Additional context It happens both with a conda installation

(env_xtb) [williamb]$ mamba list xtb
# packages in environment at /groups/kemi/williamb/opt/anaconda3/envs/env_xtb:
#
# Name                    Version                   Build  Channel
xtb                       6.4.1                hf06ca72_2    conda-forge

(env_xtb) [williamb]$ xtb --version
      -----------------------------------------------------------
     |                   =====================                   |
     |                           x T B                           |
     |                   =====================                   |
     |                         S. Grimme                         |
     |          Mulliken Center for Theoretical Chemistry        |
     |                    University of Bonn                     |
      -----------------------------------------------------------

   * xtb version 6.4.1 (23d549d) compiled by 'conda@3c73975816cd' on 2022-01-07

and a self-compiled 6.4.1 version

chem-william avatar Feb 28 '22 13:02 chem-william

Can't reproduce this behavior with the 325d1c09c393912119b5c35686bdfa3470570e83 nor the 6.4.1 release version when using Intel compilers. With GCC11 I get the following error

Molecule has the following symmetry elements: (i) (Cinf) (C2) 2*(sigma) 
It seems to be the Dinfh point group
din symmetry found (for desy threshold:  0.10E+00) used in thermo
*** stack smashing detected ***: terminated

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0  0x7f96f1efbd9f in ???
#1  0x7f96f1efbd22 in ???
#2  0x7f96f1ee5861 in ???
#3  0x7f96f1f3dd27 in ???
#4  0x7f96f1fcccc9 in ???
#5  0x7f96f1fccc93 in ???
#6  0x55f1324c9cfd in __xtb_thermo_MOD_getsymmetry
	at ../src/thermo.f90:77
#7  0x55f13234d74e in __xtb_propertyoutput_MOD_print_thermo
	at ../src/main/property.F90:1033
#8  0x55f132353ce6 in __xtb_propertyoutput_MOD_main_freq
	at ../src/main/property.F90:467
#9  0x55f13230325e in __xtb_prog_main_MOD_xtbmain
	at ../src/prog/main.F90:849
#10  0x55f1322f8fa5 in xtb_prog_primary
	at ../src/prog/primary.f90:55
#11  0x55f1322f8fa5 in main
	at ../src/prog/primary.f90:20
zsh: abort (core dumped)  ./_build_gcc11/xtb lin.mol --namespace test --ohess

awvwgk avatar Mar 02 '22 19:03 awvwgk

We recently ran into the same problems with version 6.5.1 installed as a package from conda-forge. This happens with simple linear molecules, such the N2 molecule below in an xyz file:

2

N 0.00 0.00 -0.55
N 0.00 0.00  0.55

xTB command: xtb N2.xyz --hess

After the Hessian calculation, the "stack smashing" error mentioned above appears.

On this occasion, I wanted to ask if there are any news regarding this bug?

ppinski-hqs avatar Feb 02 '23 14:02 ppinski-hqs

This is possibly related to #772, which I fixed in #774. Could you confirm?

MtoLStoN avatar Feb 23 '23 16:02 MtoLStoN

A bit late to reply, but version 6.6.1 as packaged on conda-forge still appears to have this problem.

ppinski-hqs avatar Aug 08 '23 14:08 ppinski-hqs

I tried to find the bug and this is what I found:

Cause of the bug

The problem is that in in symmetry/symmetry.f90, lines 74-77, we copy from string symbol to sfsym. Size of symbol is 6 (line 53). Size of sfsym is determined from atmp in src/thermo.f90. However, size of atmp, declared in subroutine getsymmetry in 4. Therefore, in the copying we are overwriting memory adjacent to where the string is atmp allocated, which leads to the error. This does not happen with symmetry symbols such as C3v, which have only 3 characters and the copying stops on the null byte and thus does not overwrite the adjacent memory. Therefore, the bug only happens with Dinfh an Cinfv symmetries.

Proposed fix

The simplest fix is to change line 34 in file src/thermo from Character(len=4) atmp to Character(len=6) atmp. This resolves the issue.

goxeq avatar Sep 13 '23 08:09 goxeq