Skip to content

Commit

Permalink
Fix potential overflow in raster renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 22, 2019
1 parent f92d14e commit 11f8071
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/raster/qgsrasteriterator.sip.in
Expand Up @@ -24,7 +24,7 @@ Iterator for sequentially processing raster cells.
Constructor for QgsRasterIterator, iterating over the specified ``input`` raster source.
%End

void startRasterRead( int bandNumber, int nCols, int nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback = 0 );
void startRasterRead( int bandNumber, qgssize nCols, qgssize nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback = 0 );
%Docstring
Start reading of raster band. Raster data can then be retrieved by calling readNextRasterPart until it returns ``False``.

Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/raster/qgsrasterviewport.sip.in
Expand Up @@ -19,9 +19,9 @@ struct QgsRasterViewPort

QgsPointXY mBottomRightPoint;

int mWidth;
qgssize mWidth;

int mHeight;
qgssize mHeight;

QgsRectangle mDrawnExtent;

Expand Down
6 changes: 3 additions & 3 deletions src/core/raster/qgsrasteriterator.cpp
Expand Up @@ -35,7 +35,7 @@ QgsRasterIterator::QgsRasterIterator( QgsRasterInterface *input )
}
}

void QgsRasterIterator::startRasterRead( int bandNumber, int nCols, int nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback )
void QgsRasterIterator::startRasterRead( int bandNumber, qgssize nCols, qgssize nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback )
{
if ( !mInput )
{
Expand Down Expand Up @@ -109,8 +109,8 @@ bool QgsRasterIterator::readNextRasterPartInternal( int bandNumber, int &nCols,
}

//read data block
nCols = std::min( mMaximumTileWidth, pInfo.nCols - pInfo.currentCol );
nRows = std::min( mMaximumTileHeight, pInfo.nRows - pInfo.currentRow );
nCols = static_cast< int >( std::min( static_cast< qgssize >( mMaximumTileWidth ), pInfo.nCols - pInfo.currentCol ) );
nRows = static_cast< int >( std::min( static_cast< qgssize >( mMaximumTileHeight ), pInfo.nRows - pInfo.currentRow ) );
QgsDebugMsgLevel( QStringLiteral( "nCols = %1 nRows = %2" ).arg( nCols ).arg( nRows ), 4 );

//get subrectangle
Expand Down
10 changes: 5 additions & 5 deletions src/core/raster/qgsrasteriterator.h
Expand Up @@ -48,7 +48,7 @@ class CORE_EXPORT QgsRasterIterator
* \param extent area to read
* \param feedback optional raster feedback object for cancellation/preview. Added in QGIS 3.0.
*/
void startRasterRead( int bandNumber, int nCols, int nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback = nullptr );
void startRasterRead( int bandNumber, qgssize nCols, qgssize nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback = nullptr );

/**
* Fetches details of the next part of the raster data. This method does NOT actually fetch the raster
Expand Down Expand Up @@ -154,10 +154,10 @@ class CORE_EXPORT QgsRasterIterator
//Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
struct RasterPartInfo
{
int currentCol;
int currentRow;
int nCols;
int nRows;
qgssize currentCol;
qgssize currentRow;
qgssize nCols;
qgssize nRows;
};

QgsRasterInterface *mInput = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterlayerrenderer.cpp
Expand Up @@ -187,8 +187,8 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
);

//raster viewport top left / bottom right are already rounded to int
mRasterViewPort->mWidth = static_cast<int>( mRasterViewPort->mBottomRightPoint.x() - mRasterViewPort->mTopLeftPoint.x() );
mRasterViewPort->mHeight = static_cast<int>( mRasterViewPort->mBottomRightPoint.y() - mRasterViewPort->mTopLeftPoint.y() );
mRasterViewPort->mWidth = static_cast<qgssize>( std::abs( mRasterViewPort->mBottomRightPoint.x() - mRasterViewPort->mTopLeftPoint.x() ) );
mRasterViewPort->mHeight = static_cast<qgssize>( std::abs( mRasterViewPort->mBottomRightPoint.y() - mRasterViewPort->mTopLeftPoint.y() ) );

//the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is because
//mapToPixel.mapUnitsPerPixel() is less then 1,
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterviewport.h
Expand Up @@ -50,13 +50,13 @@ struct CORE_EXPORT QgsRasterViewPort
QgsPointXY mBottomRightPoint;

//! \brief Width, number of columns to be rendered
int mWidth;
qgssize mWidth;

/**
* \brief Distance in map units from bottom edge to top edge for the part of
* the raster that is to be rendered.*/
//! \brief Height, number of rows to be rendered
int mHeight;
qgssize mHeight;

//! \brief Intersection of current map extent and layer extent
QgsRectangle mDrawnExtent;
Expand Down

0 comments on commit 11f8071

Please sign in to comment.