Commit d90c8058 authored by Olivier Teulière's avatar Olivier Teulière

* skins2: Fixed a crash occurring when a SubBitmap was specifying invalid

   coordinates and/or invalid size
parent f81175cf
...@@ -165,9 +165,15 @@ void Builder::addSubBitmap( const BuilderData::SubBitmap &rData ) ...@@ -165,9 +165,15 @@ void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
// Copy a region of the parent bitmap to the new one // Copy a region of the parent bitmap to the new one
BitmapImpl *pBmp = BitmapImpl *pBmp =
new BitmapImpl( getIntf(), rData.m_width, rData.m_height ); new BitmapImpl( getIntf(), rData.m_width, rData.m_height );
pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0, rData.m_width, bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,
rData.m_height ); rData.m_width, rData.m_height );
if( !res )
{
// Invalid sub-bitmap
delete pBmp;
msg_Warn( getIntf(), "SubBitmap %s ignored", rData.m_id.c_str() );
return;
}
m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp ); m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
} }
...@@ -178,7 +184,7 @@ void Builder::addBitmapFont( const BuilderData::BitmapFont &rData ) ...@@ -178,7 +184,7 @@ void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
new FileBitmap( getIntf(), m_pImageHandler, rData.m_file, 0 ); new FileBitmap( getIntf(), m_pImageHandler, rData.m_file, 0 );
if( !pBmp->getData() ) if( !pBmp->getData() )
{ {
// invalid bitmap // Invalid bitmap
delete pBmp; delete pBmp;
return; return;
} }
......
...@@ -39,14 +39,26 @@ BitmapImpl::~BitmapImpl() ...@@ -39,14 +39,26 @@ BitmapImpl::~BitmapImpl()
} }
void BitmapImpl::drawBitmap( const GenericBitmap &rSource, int xSrc, int ySrc, bool BitmapImpl::drawBitmap( const GenericBitmap &rSource, int xSrc, int ySrc,
int xDest, int yDest, int width, int height ) int xDest, int yDest, int width, int height )
{ {
int srcWidth = rSource.getWidth(); int srcWidth = rSource.getWidth();
uint32_t *pSrc = (uint32_t*)rSource.getData() + ySrc * srcWidth + xSrc; uint32_t *pSrc = (uint32_t*)rSource.getData() + ySrc * srcWidth + xSrc;
if( !pSrc ) if( !pSrc )
{ {
return; return false;
}
if( xSrc < 0 || xSrc + width > srcWidth ||
ySrc < 0 || ySrc + height > rSource.getHeight() )
{
msg_Warn( getIntf(), "drawBitmap: source rect too small, ignoring" );
return false;
}
if( xDest < 0 || xDest + width > m_width ||
yDest < 0 || yDest + height > m_height )
{
msg_Warn( getIntf(), "drawBitmap: dest rect too small, ignoring" );
return false;
} }
uint32_t *pDest = (uint32_t*)m_pData + yDest * m_width + xDest ; uint32_t *pDest = (uint32_t*)m_pData + yDest * m_width + xDest ;
...@@ -56,5 +68,6 @@ void BitmapImpl::drawBitmap( const GenericBitmap &rSource, int xSrc, int ySrc, ...@@ -56,5 +68,6 @@ void BitmapImpl::drawBitmap( const GenericBitmap &rSource, int xSrc, int ySrc,
pSrc += srcWidth; pSrc += srcWidth;
pDest += m_width; pDest += m_width;
} }
return true;
} }
...@@ -69,7 +69,7 @@ class BitmapImpl: public GenericBitmap ...@@ -69,7 +69,7 @@ class BitmapImpl: public GenericBitmap
virtual uint8_t *getData() const { return m_pData; } virtual uint8_t *getData() const { return m_pData; }
// Copy a region of another bitmap on this bitmap // Copy a region of another bitmap on this bitmap
void drawBitmap( const GenericBitmap &rSource, int xSrc, int ySrc, bool drawBitmap( const GenericBitmap &rSource, int xSrc, int ySrc,
int xDest, int yDest, int width, int height ); int xDest, int yDest, int width, int height );
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment