From 8df28d4f5fd2d466044c16f29edf02bfcad35e72 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 21 Jun 2024 01:07:01 -0400 Subject: [PATCH] Fix crash in symbol editor when importing Eagle symbol library. https://gitlab.com/kicad/code/kicad/-/issues/18221 --- common/io/eagle/eagle_parser.cpp | 28 +++++++++++++++---- .../symbol_editor_import_export.cpp | 9 +++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/common/io/eagle/eagle_parser.cpp b/common/io/eagle/eagle_parser.cpp index 85edd1b9d4..7c9d2312da 100644 --- a/common/io/eagle/eagle_parser.cpp +++ b/common/io/eagle/eagle_parser.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2012-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2017 CERN. * * @author Alejandro GarcĂ­a Montoro @@ -1461,7 +1461,7 @@ ELAYER::ELAYER( wxXmlNode* aLayer, IO_BASE* aIo ) : number = parseRequiredAttribute( aLayer, "number" ); name = parseRequiredAttribute( aLayer, "name" ); color = parseRequiredAttribute( aLayer, "color" ); - fill = 1; // Temporary value. + fill = parseRequiredAttribute( aLayer, "fill" ); visible = parseOptionalAttribute( aLayer, "visible" ); active = parseOptionalAttribute( aLayer, "active" ); @@ -2424,8 +2424,18 @@ ELIBRARY::ELIBRARY( wxXmlNode* aLibrary, IO_BASE* aIo ) : * * */ - name = parseRequiredAttribute( aLibrary, "name" ); - urn = parseOptionalAttribute( aLibrary, "urn" ); + + // The name and urn attributes are only valid in schematic and board files. + wxString parentNodeName; + + if( aLibrary->GetParent() ) + parentNodeName = aLibrary->GetParent()->GetName(); + + if( parentNodeName == "libraries" ) + { + name = parseRequiredAttribute( aLibrary, "name" ); + urn = parseOptionalAttribute( aLibrary, "urn" ); + } for( wxXmlNode* child = aLibrary->GetChildren(); child; child = child->GetNext() ) { @@ -2673,14 +2683,20 @@ EDRAWING::EDRAWING( wxXmlNode* aDrawing, IO_BASE* aIo ) : else if( child->GetName() == "filters" ) { for( wxXmlNode* filter = child->GetChildren(); filter; filter = filter->GetNext() ) - filters.emplace_back( std::make_unique( filter, aIo ) ); + { + if( filter->GetName() == "filter" ) + filters.emplace_back( std::make_unique( filter, aIo ) ); + } AdvanceProgressPhase(); } else if( child->GetName() == "layers" ) { for( wxXmlNode* layer = child->GetChildren(); layer; layer = layer->GetNext() ) - layers.emplace_back( std::make_unique( layer, aIo ) ); + { + if( layer->GetName() == "layer" ) + layers.emplace_back( std::make_unique( layer, aIo ) ); + } AdvanceProgressPhase(); } diff --git a/eeschema/symbol_editor/symbol_editor_import_export.cpp b/eeschema/symbol_editor/symbol_editor_import_export.cpp index 726a137170..88a287dc1a 100644 --- a/eeschema/symbol_editor/symbol_editor_import_export.cpp +++ b/eeschema/symbol_editor/symbol_editor_import_export.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -109,6 +110,12 @@ void SYMBOL_EDIT_FRAME::ImportSymbol() DisplayErrorMessage( this, msg, ioe.What() ); return; } + catch( const XML_PARSER_ERROR& ioe ) + { + msg.Printf( _( "Cannot import symbol library '%s'." ), fn.GetFullPath() ); + DisplayErrorMessage( this, msg, ioe.what() ); + return; + } if( symbols.empty() ) {