Skip to content

Commit

Permalink
Add check for int overflow on 32 bit systems
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 27, 2018
1 parent d3d1805 commit b3ed482
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -848,6 +848,15 @@ void QgsGdalProvider::readBlock( int bandNo, QgsRectangle const &extent, int pi

// Allocate temporary block
size_t bufferSize = dataSize * static_cast<size_t>( tmpWidth ) * static_cast<size_t>( tmpHeight );
#ifdef Q_PROCESSOR_X86_32
// Safety check for 32 bit systems
qint64 _buffer_size = dataSize * static_cast<qint64>( tmpWidth ) * static_cast<qint64>( tmpHeight );
if ( _buffer_size != static_cast<qint64>( bufferSize ) )
{
QgsDebugMsg( QStringLiteral( "Integer overflow calculating buffer size on a 32 bit system." ) );
return;
}
#endif
char *tmpBlock = static_cast<char *>( qgsMalloc( bufferSize ) );
if ( ! tmpBlock )
{
Expand Down

0 comments on commit b3ed482

Please sign in to comment.