Ensure PAINTER::Draw routines properly handle EDA_ITEM casting

EDA_ITEM is a child of VIEW_ITEM, so a static_cast is not appropriate,
since in some cases it could be called with a non-EDA_ITEM argument.
This was triggering an ASAN heap-buffer-overflow in GerbView.
This commit is contained in:
Ian McInerney 2020-08-15 22:06:10 +01:00
parent 0975f3817a
commit 61cdf3436b
3 changed files with 13 additions and 4 deletions

View File

@ -217,7 +217,10 @@ wxString WS_DRAW_ITEM_LIST::BuildFullText( const wxString& aTextbase )
bool KIGFX::WS_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
{
auto item = static_cast<const EDA_ITEM*>( aItem );
auto item = dynamic_cast<const EDA_ITEM*>( aItem );
if( !item )
return false;
switch( item->Type() )
{

View File

@ -165,9 +165,12 @@ SCH_PAINTER::SCH_PAINTER( GAL* aGal ) :
bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer )
{
auto item2 = static_cast<const EDA_ITEM*>( aItem );
auto item2 = dynamic_cast<const EDA_ITEM*>( aItem );
auto item = const_cast<EDA_ITEM*>( item2 );
if( !item2 )
return false;
#ifdef CONNECTIVITY_DEBUG
auto sch_item = dynamic_cast<SCH_ITEM*>( item );

View File

@ -104,7 +104,7 @@ void GERBVIEW_RENDER_SETTINGS::LoadDisplayOptions( const GBR_DISPLAY_OPTIONS& aO
COLOR4D GERBVIEW_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
{
const EDA_ITEM* item = static_cast<const EDA_ITEM*>( aItem );
const EDA_ITEM* item = dynamic_cast<const EDA_ITEM*>( aItem );
static const COLOR4D transparent = COLOR4D( 0, 0, 0, 0 );
const GERBER_DRAW_ITEM* gbrItem = nullptr;
@ -173,7 +173,10 @@ int GERBVIEW_PAINTER::getLineThickness( int aActualThickness ) const
bool GERBVIEW_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
{
const EDA_ITEM* item = static_cast<const EDA_ITEM*>( aItem );
const EDA_ITEM* item = dynamic_cast<const EDA_ITEM*>( aItem );
if( !item )
return false;
// the "cast" applied in here clarifies which overloaded draw() is called
switch( item->Type() )