Skip to content
Permalink
Browse files

PG raster: fix crash on invalid extent

Fixes #39779
  • Loading branch information
elpaso committed Nov 3, 2020
1 parent 47a08a4 commit 1c22933405abe09f4ac23664df506e8ee011c041
@@ -131,7 +131,6 @@ QgsPostgresRasterProvider::QgsPostgresRasterProvider( const QgsPostgresRasterPro
, mRasterColumn( other.mRasterColumn )
, mSchemaName( other.mSchemaName )
, mSqlWhereClause( other.mSqlWhereClause )
, mExtent( other.mExtent )
, mUseEstimatedMetadata( other.mUseEstimatedMetadata )
, mDataTypes( other.mDataTypes )
, mDataSizes( other.mDataSizes )
@@ -1147,6 +1146,11 @@ bool QgsPostgresRasterProvider::init()
// is tiled?
mIsTiled = ( mWidth != mTileWidth ) || ( mHeight != mTileHeight );

if ( ! checkExtent() )
{
return false;
}

// Detect overviews
findOverviews();
return initFieldsAndTemporal( );
@@ -1368,6 +1372,12 @@ bool QgsPostgresRasterProvider::init()
QStringLiteral( "PostGIS" ), Qgis::Critical );
return false;
}

if ( ! checkExtent() )
{
return false;
}

return initFieldsAndTemporal( );
}

@@ -1909,6 +1919,23 @@ QStringList QgsPostgresRasterProvider::parseUriKey( const QString &key )
return cols;
}

bool QgsPostgresRasterProvider::checkExtent()
{
// Last check for extent and crs (see GH #39779 crash)
if ( ! mCrs.bounds().isEmpty() )
{
const QgsCoordinateTransform transformer { mCrs, QgsCoordinateReferenceSystem( 4326 ), transformContext() };
const QgsRectangle transformedExtent { transformer.transform( mExtent ) };
if ( ! mCrs.bounds().contains( transformedExtent ) )
{
QgsMessageLog::logMessage( tr( "The extent is outside the CRS bounds" ),
QStringLiteral( "PostGIS" ), Qgis::Critical );
return false;
}
}
return true;
}

QgsPostgresProvider::Relkind QgsPostgresRasterProvider::relkind() const
{
if ( mIsQuery || !connectionRO() )
@@ -93,8 +93,6 @@ class QgsPostgresRasterProvider : public QgsRasterDataProvider
QString mSchemaName;
//! SQL statement used to limit the features retrieved (subset string)
QString mSqlWhereClause;
//! Rectangle that contains the extent (bounding box) of the layer
mutable QgsRectangle mExtent;
//! Use estimated metadata. Uses fast table counts, geometry type and extent determination
bool mUseEstimatedMetadata = true;
//! Error information
@@ -234,6 +232,8 @@ class QgsPostgresRasterProvider : public QgsRasterDataProvider

QStringList parseUriKey( const QString &key );

bool checkExtent();

public:
};

0 comments on commit 1c22933

Please sign in to comment.
You can’t perform that action at this time.