pcbnew action plugin can crash kicad

Bug #1843700 reported by Dino Ghilardi
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
KiCad
Fix Committed
Undecided
Unassigned

Bug Description

In master branch a python script can crash pcbnew.

Tested with ReplicateLayout plugin from

https://github.com/MitjaNemec/Kicad_action_plugins

To replicate it:

-Install the replicateLayout plugin
-Open the attached project
-Open pcbnew
-Select R15
-Tools->External Plugins->Replicate Layout
-in the dialog in "Hierarchy level select file5D...FA.sch
-Click OK
-Now the layout seems correctly replicated but exiting pcbnew (don't save) there is a segfault.
If, after running the script you try to undo it with ctrl-z you can get some other weird behaviour (like some new components without any label and not selectable on the board).

On 5.1.2 and 5.1.4 stable versions the script seems to work correctly (although it needed some modifications since the "Flip" function in dev version gets 3 arguments and in stable it did get two. May be overloading it with the old behaviour can help in not braking old scripts when V6 will be released)

gdb reports:

Thread 1 "kicad" received signal SIGSEGV, Segmentation fault.
0x00007ffff3b11078 in main_arena () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) backtrace
#0 0x00007ffff3b11078 in main_arena () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007fffd34da849 in PICKED_ITEMS_LIST::ClearListAndDeleteItems() () from /home/dinoghi/SANDBOXKICAD5/usr/bin/_pcbnew.kiface
#2 0x00007fffd2e74e80 in PCB_SCREEN::ClearUndoORRedoList(UNDO_REDO_CONTAINER&, int) () from /home/dinoghi/SANDBOXKICAD5/usr/bin/_pcbnew.kiface
#3 0x00007fffd31b09c9 in BASE_SCREEN::ClearUndoRedoList() () from /home/dinoghi/SANDBOXKICAD5/usr/bin/_pcbnew.kiface
#4 0x00007fffd2deb985 in PCB_EDIT_FRAME::Clear_Pcb(bool, bool) () from /home/dinoghi/SANDBOXKICAD5/usr/bin/_pcbnew.kiface
#5 0x00007fffd2e1e5ef in PCB_EDIT_FRAME::OnCloseWindow(wxCloseEvent&) () from /home/dinoghi/SANDBOXKICAD5/usr/bin/_pcbnew.kiface
#6 0x00007ffff634440e in wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) const ()
   from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#7 0x00007ffff64c9ea5 in wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) ()
   from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#8 0x00007ffff64c9f9b in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#9 0x00007ffff64ca34b in wxEvtHandler::TryHereOnly(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#10 0x00007fffd3462e99 in EDA_BASE_FRAME::ProcessEvent(wxEvent&) () from /home/dinoghi/SANDBOXKICAD5/usr/bin/_pcbnew.kiface
#11 0x00007ffff64ca153 in wxEvtHandler::DoTryChain(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#12 0x00007ffff64ca435 in wxEvtHandler::ProcessEvent(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#13 0x00007ffff64ca1a7 in wxEvtHandler::SafelyProcessEvent(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#14 0x00007ffff6e57be7 in wxWindowBase::Close(bool) () from /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0
#15 0x00007ffff634440e in wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) const ()
   from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#16 0x00007ffff64c9ea5 in wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) ()
   from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#17 0x00007ffff64c9f9b in wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#18 0x00007ffff64ca34b in wxEvtHandler::TryHereOnly(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#19 0x00007fffd3462e99 in EDA_BASE_FRAME::ProcessEvent(wxEvent&) () from /home/dinoghi/SANDBOXKICAD5/usr/bin/_pcbnew.kiface
#20 0x00007ffff64ca153 in wxEvtHandler::DoTryChain(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#21 0x00007ffff64ca435 in wxEvtHandler::ProcessEvent(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#22 0x00007ffff6e562f8 in wxWindowBase::TryAfter(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0
#23 0x00007ffff64ca1a7 in wxEvtHandler::SafelyProcessEvent(wxEvent&) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#24 0x00007ffff6dfb2df in wxMenuBase::SendEvent(int, int) () from /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0
#25 0x00007ffff6cdec1b in ?? () from /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0
#26 0x00007ffff2c35f75 in g_closure_invoke () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#27 0x00007ffff2c47f82 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#28 0x00007ffff2c50bdc in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#29 0x00007ffff2c50fbf in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
---Type <return> to continue, or q <return> to quit---
#30 0x00007ffff337662e in gtk_widget_activate () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#31 0x00007ffff32714dd in gtk_menu_shell_activate_item () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#32 0x00007ffff3271846 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#33 0x00007ffff325f7bc in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#34 0x00007ffff2c35f75 in g_closure_invoke () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#35 0x00007ffff2c4837d in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#36 0x00007ffff2c5067f in g_signal_emit_valist () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#37 0x00007ffff2c50fbf in g_signal_emit () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#38 0x00007ffff33778ac in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#39 0x00007ffff325df84 in gtk_propagate_event () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#40 0x00007ffff325e33b in gtk_main_do_event () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#41 0x00007ffff2ed3cbc in ?? () from /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
#42 0x00007ffff21ac7f7 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#43 0x00007ffff21aca60 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#44 0x00007ffff21acd82 in g_main_loop_run () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#45 0x00007ffff325d3b7 in gtk_main () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#46 0x00007ffff6c41e65 in wxGUIEventLoop::DoRun() () from /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0
#47 0x00007ffff638627b in wxEventLoopBase::Run() () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#48 0x00007ffff634b776 in wxAppConsoleBase::MainLoop() () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#49 0x00005555555d3536 in ?? ()
#50 0x00007ffff63d7cd0 in wxEntry(int&, wchar_t**) () from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#51 0x00005555555af568 in ?? ()
#52 0x00007ffff37972e1 in __libc_start_main (main=0x5555555af540, argc=1, argv=0x7fffffffe158, init=<optimized out>, fini=<optimized out>,
    rtld_fini=<optimized out>, stack_end=0x7fffffffe148) at ../csu/libc-start.c:291
#53 0x00005555555bac8a in _start ()

*******************************************

Application: Pcbnew
Version: (5.99.0-114-g271465a64-dirty), release build
Libraries:
    wxWidgets 3.0.2
    libcurl/7.52.1 OpenSSL/1.0.2s zlib/1.2.8 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) libssh2/1.7.0 nghttp2/1.18.1 librtmp/2.3
Platform: Linux 4.9.0-8-amd64 x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.69.0
    OpenCASCADE Community Edition: 6.8.0
    Curl: 7.52.1
    Compiler: GCC 6.3.0 with C++ ABI 1010

Build settings:
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_PYTHON3=OFF
    KICAD_SCRIPTING_WXPYTHON=ON
    KICAD_SCRIPTING_WXPYTHON_PHOENIX=OFF
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON

Tags: pcbnew python
Revision history for this message
Dino Ghilardi (dino-ghilardi) wrote :
Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

@Dino, does this plugin work correctly in the 5.1 branch? If not, it could be an issue with the plugin. The Python plugin exposes the low level internals of the board editor so you can write a script that can crash KiCad.

Changed in kicad:
status: New → Incomplete
Revision history for this message
Dino Ghilardi (dino-ghilardi) wrote :

Yes, On 5.1.2 and 5.1.4 stable versions the script works correctly (although it needed some modifications since the "Flip" function in dev version gets 3 arguments and in stable it did get two. (May be overloading it with the old behaviour can help in not braking old scripts when V6 will be released).

Revision history for this message
Dino Ghilardi (dino-ghilardi) wrote :

In stable branch you can undo the operation with ctrl-z without issues, while in dev version it does strange things, as if the "undo" list gets corrupted (just an hypothesis without proof since I did not look into the code to see how undo is implemented).
Undoing in dev version after running the script I get on the board two "R10" resistors one of which is not selectable and then exiting pcbnew I get the segfault.

Revision history for this message
Dino Ghilardi (dino-ghilardi) wrote :

Also just exiting pcbnew after running the script I get the segfault.

Revision history for this message
Ian McInerney (imcinerney) wrote :

@Dino, unfortunately as we get further into the v6 development cycle the plugins designed for 5.1 might have problems. The changes to the internal functions in Pcbnew are needed to continue with the feature development, and trying to make it so they are backwards compatible with the Python interface for 5.1 is going to be a nightmare of duplicated code & possible bugs. I believe there is a plan to isolate the Python interface from the internals of Pcbnew so that in the future these sorts of internal changes won't affect the plugins as much, and that will probably require plugins to be rewritten (it isn't known yet what the full API will look like).

Revision history for this message
Dino Ghilardi (dino-ghilardi) wrote :

Probably this is another effect of of Bug #1844880 reported by DDuck007 on 2019-09-21

Seems that commit 840c77fa9c7500dd5ad0b326eed8f108cde0fc47 solved also this, so this can be closed.

Cheers,
Dino.

Changed in kicad:
milestone: none → 6.0.0-rc1
status: Incomplete → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.