neuronsimulator / nrn

NEURON Simulator
http://nrn.readthedocs.io
Other
404 stars 118 forks source link

nocmodl segfaults when translating cdp5_CR_CAM.mod from ModelDB model #265584 #1994

Open pramodk opened 2 years ago

pramodk commented 2 years ago

Overview of the issue

When trying to translate cdp5_CR_CAM.mod I see that nocmodl segfaults:

$ nocmodl ./265584/04_GrC_2020_accelerating/mod_files/cdp5_CR_CAM.mod
Translating ./265584/04_GrC_2020_accelerating/mod_files/cdp5_CR_CAM.mod into ./265584/04_GrC_2020_accelerating/mod_files/cdp5_CR_CAM.cpp
NEURON's CVode method ignores conservation
[2]    28499 segmentation fault  /Users/kumbhar/workarena/repos/bbp/nrn/build_master/install/bin/nocmodl

Looking at the backtrace I see:

    frame #1: 0x00007ff804e9de9a libsystem_c.dylib`__vfprintf + 5000
    frame #2: 0x00007ff804eaa620 libsystem_c.dylib`vsprintf_l + 184
    frame #3: 0x00007ff804eb0490 libsystem_c.dylib`sprintf + 160
    frame #4: 0x000000010000b7bf nocmodl`kinlist(Symbol*, Rlist*) + 191
    frame #5: 0x000000010000b0a1 nocmodl`kinetic_intmethod(Symbol*, char*) + 513
    frame #6: 0x000000010000d9f2 nocmodl`cvode_kinetic(Item*, Symbol*, int, int) + 146
    frame #7: 0x00000001000224bd nocmodl`solvhandler() + 1341
    frame #8: 0x000000010000e751 nocmodl`main + 513
    frame #9: 0x000000010006951e dyld`start + 462
(lldb)

This also happens with NEURON 8.0 release.

Expected result/behavior

MOD file should be translated without errors.

NEURON setup

Minimal working example - MWE

Logs

See above

nrnhines commented 2 years ago

For reference the address sanitizer on a Mac M1 gives:

% nocmodl *.mod
Translating cdp5_CR_CAM.mod into cdp5_CR_CAM.cpp
=================================================================
==17174==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x000103803d78 at pc 0x000100561d0c bp 0x00016f8ab790 sp 0x00016f8ab788
WRITE of size 8 at 0x000103803d78 thread T0
    #0 0x100561d08 in massagekinetic(Item*, Item*, Item*, Item*, int) kinetic.cpp:479
    #1 0x1005c09dc in yyparse() parse1.ypp:1057
    #2 0x10056e794 in main modl.cpp:163
    #3 0x100971088 in start+0x204 (dyld:arm64e+0x5088)

0x000103803d78 is located 8 bytes to the left of 240-byte region [0x000103803d80,0x000103803e70)
allocated by thread T0 here:
    #0 0x100d73b58 in wrap_malloc+0x94 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x3fb58)
    #1 0x10056d91c in emalloc(unsigned int) list.cpp:220
    #2 0x1005618d8 in massagekinetic(Item*, Item*, Item*, Item*, int) kinetic.cpp:464
    #3 0x1005c09dc in yyparse() parse1.ypp:1057
    #4 0x10056e794 in main modl.cpp:163
    #5 0x100971088 in start+0x204 (dyld:arm64e+0x5088)
nrnhines commented 2 years ago

Looking at the COMPARTMENT statements in the mod file I see that at least CR_1C_2N is listed twice. So I'm guessing eliminating duplicates will fix the issue. If it does, there should be an error message for duplicate STATE in a COMPARTMENT statement.

nrnhines commented 2 years ago

Hmm. After adding a printf for SYM(q1)->used - 1, I see that mg is declared as a STATE, and appears in a COMPARTMENT statement,but it does not appear in any kinetic equation. Making it ASSIGNED and removing it from the COMPARTMENT statement, then causes nocmodl to end with

Error: cao used in USEION statement can not be re-declared in a CONSTANT block at line 398 in file cdp5_CR_CAM.mod
^

Replacing the CONSTANT statement with ASSIGNED { cao (mM) } allows nrnivodl to succeed and nrniv can load the dll.

Additional mechanisms from files
 "cdp5_CR_CAM.mod"
oc>
nrnhines commented 2 years ago

Forgive the format but the above uses

  COMPARTMENT diam*diam*vrat {ca Buff1 Buff1_ca Buff2 Buff2_ca
BTC BTC_ca DMNPE DMNPE_ca
CR
 CR_0C_1N 
 CR_0C_2N
 CR_1C_0N
 CR_1C_1N
 CR_1C_2N
 CR_2C_0N
 CR_2C_1N
 CR_2C_2N
}
SteMasoli commented 2 years ago

CR_1C_2N

Ops... CR_2C_1N is duplicated too. To much copy and past.

Back in 2019/2020 I had no issue compiling it but if it is not working correctly with the current version of NEURON, I'll update the model accordingly.

And CR_1V is missing from COMPARTMENT.

SteMasoli commented 2 years ago

I have checked my models with NEURON 8.2.1, without the duplicated variables and with the missing one. The differences in physiological activity are negligible.

Thank you @pramodk