eeschema: Segfault when loading schematic with non-existing subsheet files
Description
When opening a schematic in eeschema that has a subsheet with a Sheetfile
property with a filename that does not exist, eeschema crashes segfaults accessing the null pointer. This happens both in standalone mode and when openend from the project window.
I feel like this might be the root cause of #15201 (closed)
GDB backtrace:
Click to expand
Thread 1 "eeschema" received signal SIGSEGV, Segmentation fault. __GI___fileno (fp=0x0) at fileno.c:35 35 if (!(fp->_flags & _IO_IS_FILEBUF) || _IO_fileno (fp) < 0) (gdb) bt #0 __GI___fileno (fp=0x0) at fileno.c:35 #1 0x00007fffe64b4a6d in KIPLATFORM::IO::SeqFOpen(wxString const&, wxString const&) (aPath=..., aMode=...) at /home/jaseg/ref/kicad/libs/kiplatform/gtk/io.cpp:33 #2 0x00007fffe61273b6 in FILE_LINE_READER::FILE_LINE_READER(wxString const&, unsigned int, unsigned int) (this=0x7fffffffa7b0, aFileName=..., aStartingLineNumber=0, aMaxLineLength=1000000) at /home/jaseg/ref/kicad/common/richio.cpp:213 #3 0x00007fffe5c8bcca in SCH_SEXPR_PLUGIN::loadFile(wxString const&, SCH_SHEET*) (this=0x55555e645ee0, aFileName=..., aSheet=0x5555566c02a0) at /home/jaseg/ref/kicad/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp:297 #4 0x00007fffe5c8b20b in SCH_SEXPR_PLUGIN::loadHierarchy(SCH_SHEET_PATH const&, SCH_SHEET*) (this=0x55555e645ee0, aParentSheetPath=..., aSheet=0x5555566c02a0) at /home/jaseg/ref/kicad/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp:246 #5 0x00007fffe5c8b54d in SCH_SEXPR_PLUGIN::loadHierarchy(SCH_SHEET_PATH const&, SCH_SHEET*) (this=0x55555e645ee0, aParentSheetPath=..., aSheet=0x55555e59aa80) at /home/jaseg/ref/kicad/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp:283 #6 0x00007fffe5c8a275 in SCH_SEXPR_PLUGIN::Load(wxString const&, SCHEMATIC*, SCH_SHEET*, STRING_UTF8_MAP const*) (this=0x55555e645ee0, aFileName=..., aSchematic=0x555556e30080, aAppendToMe=0x0, aProperties=0x0) at /home/jaseg/ref/kicad/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp:155 #7 0x00007fffe593e598 in SCH_EDIT_FRAME::OpenProjectFiles(std::vector > const&, int) (this=0x555556baa3e0, aFileSet=std::vector of length 1, capacity 1 = {...}, aCtl=0) at /home/jaseg/ref/kicad/eeschema/files-io.cpp:247 #8 0x000055555571e1c9 in PGM_SINGLE_TOP::OnPgmInit() (this=0x555555f266c0 ) at /home/jaseg/ref/kicad/common/single_top.cpp:409 #9 0x000055555572231d in APP_SINGLE_TOP::OnInit() (this=0x555555fd62d0) at /home/jaseg/ref/kicad/common/single_top.cpp:182 #10 0x000055555572069f in wxAppConsoleBase::CallOnInit() (this=0x555555fd62d0) at /usr/include/wx-3.2/wx/app.h:93 #11 0x00007ffff710f0d2 in wxEntry(int&, wchar_t**) () at /usr/lib/libwx_baseu-3.2.so.0 #12 0x000055555571da73 in main(int, char**) (argc=2, argv=0x7fffffffd3c8) at /home/jaseg/ref/kicad/common/single_top.cpp:286 (gdb) up #1 0x00007fffe64b4a6d in KIPLATFORM::IO::SeqFOpen (aPath=..., aMode=...) at /home/jaseg/ref/kicad/libs/kiplatform/gtk/io.cpp:33 33 posix_fadvise( fileno( fp ), 0, 0, POSIX_FADV_SEQUENTIAL ); (gdb) p aPath $1 = (const wxString &) @0x7fffffffae30: {m_impl = L"/tmp/rgb_drv_ch2.kicad_sch", m_convertedToChar = { m_str = 0x555556af3260 "/tmp/rgb_drv_ch2.kicad_sch", m_len = 26}} (gdb) quit
Steps to reproduce
Easiest is to copy a file with subsheets into a different folder, and try to open it there.
Test file: test.kicad_sch
KiCad Version
recent nightly build, version 7.99.0-1902-g07414710
Application: KiCad Schematic Editor x86_64 on x86_64
Version: 7.99.0-unknown, debug build
Libraries:
wxWidgets 3.2.2
FreeType 2.13.0
HarfBuzz 7.3.0
FontConfig 2.14.2
libcurl/8.1.2 OpenSSL/3.1.1 zlib/1.2.13 brotli/1.0.9 zstd/1.5.5 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh2/1.10.0 nghttp2/1.54.0
Platform: Linux 6.3.8-arch1-1 x86_64, 64 bit, Little endian, wxGTK, gnome, wayland
Build Info:
Date: Jul 16 2023 14:33:04
wxWidgets: 3.2.2 (wchar_t,wx containers) GTK+ 3.24
Boost: 1.81.0
OCC: 7.6.3
Curl: 8.1.2
ngspice: 40
Compiler: GCC 13.1.1 with C++ ABI 1018
Build settings:
KICAD_USE_EGL=ON
KICAD_STDLIB_DEBUG=OFF
KICAD_STDLIB_LIGHT_DEBUG=OFF
KICAD_SANITIZE_ADDRESS=OFF
KICAD_SANITIZE_THREADS=OFF