symengine / SymEngine.jl

Julia wrappers of SymEngine
MIT License
192 stars 43 forks source link

get_name causes a segfault if used with someting other than FunctionSymbol #245

Open PerformanceCoder opened 2 years ago

PerformanceCoder commented 2 years ago

Hi!

Found a bug (crashes terminal immediately) while working with SymEngine. Steps to reproduce:

  1. Create file TestPolygon.jl
  2. insert this code in TestPolygon:
    
    using SymEngine

x = symbols("x") mult = sin(2.0*x) name = get_name(mult) print(name)

3. Launch using ```julia TestPolygon.jl```

After executing this file I get a segfault with repeation rate about 80% (1 of 5 launches completes without errors).

Log file (windows 10, Julia 1.6.1)

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks. Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffc15bf460a -- memcpy at C:\Windows\System32\msvcrt.dll (unknown line) in expression starting at C:\testpolygon.jl:9 memcpy at C:\Windows\System32\msvcrt.dll (unknown line) _ZNSt7cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag.isra.498 at C:\Users\username.julia\artifacts\635e58d3b6452a234dbf29dbac9259f2a3f7947e\bin\libsymengine-0.8.dll (unknown line) function_symbol_get_name at C:\Users\username.julia\artifacts\635e58d3b6452a234dbf29dbac9259f2a3f7947e\bin\libsymengine-0.8.dll (unknown line) get_name at C:\Users\username.julia\packages\SymEngine\OE2Ff\src\types.jl:260 jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined] do_call at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:115 eval_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:204 eval_stmt_value at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:155 [inlined] eval_body at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:576 jl_interpret_toplevel_thunk at /cygdrive/c/buildbot/worker/package_win64/build/src\interpreter.c:670 jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:877 jl_toplevel_eval_flex at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:825 jl_toplevel_eval at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:886 [inlined] jl_toplevel_eval_in at /cygdrive/c/buildbot/worker/package_win64/build/src\toplevel.c:929 eval at .\boot.jl:360 [inlined] include_string at .\loading.jl:1094 _include at .\loading.jl:1148 include at .\Base.jl:386 exec_options at .\client.jl:285 _start at .\client.jl:485 jfptrstart_22922.clone_1 at C:\Users\username\AppData\Local\Programs\Julia-1.6.1\lib\julia\sys.dll (unknown line) jl_apply at /cygdrive/c/buildbot/worker/package_win64/build/src\julia.h:1703 [inlined] true_main at /cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:560 repl_entrypoint at /cygdrive/c/buildbot/worker/package_win64/build/src\jlapi.c:702 mainCRTStartup at /cygdrive/c/buildbot/worker/package_win64/build/cli\loader_exe.c:51 BaseThreadInitThunk at C:\Windows\System32\KERNEL32.DLL (unknown line) RtlUserThreadStart at C:\Windows\SYSTEM32\ntdll.dll (unknown line) Allocations: 2648 (Pool: 2638; Big: 10); GC: 0


The problem reproduces in Linux: log file (Manjaro KDE, Julia 1.7.0). Interestingly, I can reproduce it only after 4-5 launches in terminal.

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc

signal (6): Аварийный останов in expression starting at /home/username/TestPolygon.jl:5 gsignal at /usr/bin/../lib/libc.so.6 (unknown line) abort at /usr/bin/../lib/libc.so.6 (unknown line) verbose_terminate_handler at /build/gcc/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95 terminate at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48 terminate at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58 cxa_throw at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95 operator new at /build/gcc/src/gcc/libstdc++-v3/libsupc++/new_op.cc:54 _ZNSt7cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag.isra.365 at /home/username/.julia/artifacts/8192a4fc347dc5d7c32b3acfde7af2074fe436a6/lib/libsymengine.so (unknown line) function_symbol_get_name at /home/username/.julia/artifacts/8192a4fc347dc5d7c32b3acfde7af2074fe436a6/lib/libsymengine.so (unknown line) get_name at /home/username/.julia/packages/SymEngine/OE2Ff/src/types.jl:260 unknown function (ip: 0x7f206ef675f5) unknown function (ip: 0x7f206ef66fd4) unknown function (ip: 0x7f206ef67cb4) unknown function (ip: 0x7f206ef689d0) unknown function (ip: 0x7f206ef85287) unknown function (ip: 0x7f206ef85ebe) jl_toplevel_eval_in at /usr/bin/../lib/julia/libjulia-internal.so.1 (unknown line) unknown function (ip: 0x7f2057e00ac7) unknown function (ip: 0x7f2057f096e1) unknown function (ip: 0x7f2057f09182) unknown function (ip: 0x7f2058086ecc) unknown function (ip: 0x7f2057ff7022) unknown function (ip: 0x7f2057ff7178) unknown function (ip: 0x7f206efabd0e) jl_repl_entrypoint at /usr/bin/../lib/julia/libjulia-internal.so.1 (unknown line) main at julia (unknown line) __libc_start_main at /usr/bin/../lib/libc.so.6 (unknown line) _start at julia (unknown line) Allocations: 2720 (Pool: 2709; Big: 11); GC: 0 zsh: abort (core dumped) julia TestPolygon.jl



I understand that "get_name" should be used only with functions, but maybe this code should raise an exception in case of incorrect input?