From 09f97aa2869d9b7a5b41048ede21d4cff712bb56 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 4 Jan 2020 12:33:14 +0100 Subject: [PATCH 1/2] Fixed #466 (Segfault when accessing a wrong layer tab) --- src/laybasic/laybasic/layLayoutView.cc | 14 ++++++++++++++ testdata/ruby/layLayoutView.rb | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/laybasic/laybasic/layLayoutView.cc b/src/laybasic/laybasic/layLayoutView.cc index f437fd5102..5da52d93ba 100644 --- a/src/laybasic/laybasic/layLayoutView.cc +++ b/src/laybasic/laybasic/layLayoutView.cc @@ -1935,6 +1935,10 @@ LayoutView::expand_properties (unsigned int index, const std::map &map void LayoutView::replace_layer_node (unsigned int index, const LayerPropertiesConstIterator &iter, const LayerPropertiesNode &node) { + if (index >= layer_lists ()) { + return; + } + // if the source specification changed, a redraw is required if (*iter != node) { @@ -1968,6 +1972,10 @@ LayoutView::replace_layer_node (unsigned int index, const LayerPropertiesConstIt void LayoutView::set_properties (unsigned int index, const LayerPropertiesConstIterator &iter, const LayerProperties &props) { + if (index >= layer_lists ()) { + return; + } + // if the source specification changed, a redraw is required const LayerProperties &l = *iter; if (l != props) { @@ -2007,6 +2015,8 @@ LayoutView::set_properties (unsigned int index, const LayerPropertiesConstIterat const LayerPropertiesNode & LayoutView::insert_layer (unsigned int index, const LayerPropertiesConstIterator &before, const LayerPropertiesNode &node) { + tl_assert (index < layer_lists ()); + if (transacting ()) { manager ()->queue (this, new OpInsertLayerProps (index, (unsigned int) before.uint (), node)); } else if (manager () && ! replaying ()) { @@ -2032,6 +2042,10 @@ LayoutView::insert_layer (unsigned int index, const LayerPropertiesConstIterator void LayoutView::delete_layer (unsigned int index, LayerPropertiesConstIterator &iter) { + if (index >= layer_lists ()) { + return; + } + lay::LayerPropertiesNode orig = *iter; if (mp_control_panel && index == current_layer_list ()) { diff --git a/testdata/ruby/layLayoutView.rb b/testdata/ruby/layLayoutView.rb index 3180b83c5e..cdad47fa88 100644 --- a/testdata/ruby/layLayoutView.rb +++ b/testdata/ruby/layLayoutView.rb @@ -397,6 +397,9 @@ def test_3 lp.fill_color = 0xffff31cc assert_equal(lv.begin_layers.current.fill_color, 0xffff31cc) + # should not segfault + lv.insert_layer(42, lv.begin_layers(42)) + end end From aa268d3768e0f9eb2a931f159225723499df10fc Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 4 Jan 2020 12:38:06 +0100 Subject: [PATCH 2/2] Updated unit test. --- testdata/ruby/layLayoutView.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/testdata/ruby/layLayoutView.rb b/testdata/ruby/layLayoutView.rb index cdad47fa88..de35fd02c6 100644 --- a/testdata/ruby/layLayoutView.rb +++ b/testdata/ruby/layLayoutView.rb @@ -398,7 +398,11 @@ def test_3 assert_equal(lv.begin_layers.current.fill_color, 0xffff31cc) # should not segfault - lv.insert_layer(42, lv.begin_layers(42)) + begin + lv.insert_layer(42, lv.begin_layers(42)) + assert_equal(true, false) + rescue => ex + end end