Skip to content
Permalink
Browse files
Check return from QgsPalLabeling::prepareGeometry before dereference
Fixes #15507

Includes automated test.
  • Loading branch information
strk committed May 16, 2017
1 parent 4dab1f8 commit 126cf5f100abb077fd0ba611cb1653583dd898cd
Showing with 48 additions and 2 deletions.
  1. +7 −2 src/core/qgspallabeling.cpp
  2. +41 −0 tests/src/core/testqgslabelingenginev2.cpp
@@ -2529,8 +2529,13 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
if ( QgsPalLabeling::geometryRequiresPreparation( &permissibleZone, context, ct, doClip ? extentGeom : nullptr ) )
{
QgsGeometry* preparedZone = QgsPalLabeling::prepareGeometry( &permissibleZone, context, ct, doClip ? extentGeom : nullptr );
permissibleZone = *preparedZone;
delete preparedZone;
if ( preparedZone )
{
// QgsPalLabeling::prepareGeometry may return NULL on
// QgsCsException exception
permissibleZone = *preparedZone;
delete preparedZone;
}
}
}

@@ -13,6 +13,8 @@
* *
***************************************************************************/

#include <memory>

#include <QtTest/QtTest>

#include <qgsapplication.h>
@@ -45,6 +47,7 @@ class TestQgsLabelingEngineV2 : public QObject
void testEncodeDecodePositionOrder();
void testSubstitutions();
void testCapitalization();
void testRegisterFeatureUnprojectible();

private:
QgsVectorLayer* vl;
@@ -538,5 +541,43 @@ bool TestQgsLabelingEngineV2::imageCheck( const QString& testName, QImage &image
return resultFlag;
}

// See https://issues.qgis.org/issues/15507
void TestQgsLabelingEngineV2::testRegisterFeatureUnprojectible()
{
QgsPalLayerSettings settings;
settings.fieldName = QString( "'aa label'" );
settings.isExpression = true;
settings.fitInPolygonOnly = true;

std::unique_ptr< QgsVectorLayer> vl2( new QgsVectorLayer( "polygon?crs=epsg:4326&field=id:integer", "vl", "memory" ) );
QgsVectorLayerLabelProvider* provider = new QgsVectorLayerLabelProvider( vl2.get(), "test", true, &settings );
QgsFeature f( vl2->fields(), 1 );

QString wkt1 = "POLYGON((0 0,8 0,8 -90,0 0))";
f.setGeometry( QgsGeometry().fromWkt( wkt1 ) );

// make a fake render context
QSize size( 640, 480 );
QgsMapSettings mapSettings;
mapSettings.setCrsTransformEnabled( true );
QgsCoordinateReferenceSystem tgtCrs;
tgtCrs.createFromString( "EPSG:3857" );
mapSettings.setDestinationCrs( tgtCrs );

mapSettings.setOutputSize( size );
mapSettings.setExtent( vl2->extent() );
mapSettings.setLayers( QStringList() << vl2->id() );
mapSettings.setOutputDpi( 96 );
QgsRenderContext context = QgsRenderContext::fromMapSettings( mapSettings );
QStringList attributes;
QgsLabelingEngineV2 engine;
engine.setMapSettings( mapSettings );
engine.addProvider( provider );
provider->prepare( context, attributes );

provider->registerFeature( f, context );
QCOMPARE( provider->mLabels.size(), 0 );
}

QTEST_MAIN( TestQgsLabelingEngineV2 )
#include "testqgslabelingenginev2.moc"

0 comments on commit 126cf5f

Please sign in to comment.