Skip to content

Commit

Permalink
Fix assert with negative QVector size in transformBoundingBox
Browse files Browse the repository at this point in the history
This fixes #32302 by insuring that the multilication of nXPoints and nYPoints
doesn't result in overflown (and threfore negative) int value
  • Loading branch information
nirvn committed Oct 18, 2019
1 parent a11903a commit f393c11
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/core/qgscoordinatetransform.cpp
Expand Up @@ -491,19 +491,18 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r

// 64 points (<=2.12) is not enough, see #13665, for EPSG:4326 -> EPSG:3574 (say that it is a hard one),
// are decent result from about 500 points and more. This method is called quite often, but
// even with 1000 points it takes < 1ms
// even with 1000 points it takes < 1ms.
// TODO: how to effectively and precisely reproject bounding box?
const int nPoints = 1000;
double d = std::sqrt( ( rect.width() * rect.height() ) / std::pow( std::sqrt( static_cast< double >( nPoints ) ) - 1, 2.0 ) );
int nXPoints = static_cast< int >( std::ceil( rect.width() / d ) ) + 1;
int nYPoints = static_cast< int >( std::ceil( rect.height() / d ) ) + 1;
int nXPoints = std::min( static_cast< int >( std::ceil( rect.width() / d ) ) + 1, 1000 );
int nYPoints = std::min( static_cast< int >( std::ceil( rect.height() / d ) ) + 1, 1000 );

QgsRectangle bb_rect;
bb_rect.setMinimal();

// We're interfacing with C-style vectors in the
// end, so let's do C-style vectors here too.

QVector<double> x( nXPoints * nYPoints );
QVector<double> y( nXPoints * nYPoints );
QVector<double> z( nXPoints * nYPoints );
Expand Down

0 comments on commit f393c11

Please sign in to comment.