From d5de4bb5c7343bf46dad7b107d2894c54bcf9ab7 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Fri, 1 Apr 2022 23:13:38 -0400 Subject: [PATCH] Catch memory exhaustion trying to import large DXFs See https://gitlab.com/kicad/code/kicad/-/issues/11308 (cherry picked from commit 9f8c0a818597f23e1f82cb834c6e0b8501dd28e0) --- pcbnew/import_gfx/dxf_import_plugin.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pcbnew/import_gfx/dxf_import_plugin.cpp b/pcbnew/import_gfx/dxf_import_plugin.cpp index ce9ff76f96..287509327f 100644 --- a/pcbnew/import_gfx/dxf_import_plugin.cpp +++ b/pcbnew/import_gfx/dxf_import_plugin.cpp @@ -118,7 +118,15 @@ DXF_IMPORT_PLUGIN::~DXF_IMPORT_PLUGIN() bool DXF_IMPORT_PLUGIN::Load( const wxString& aFileName ) { - return ImportDxfFile( aFileName ); + try + { + return ImportDxfFile( aFileName ); + } + catch( const std::bad_alloc& ) + { + reportMsg( _( "Memory was exhausted trying to load the DXF, it may be too large." ) ); + return false; + } }