Skip to content

Commit 7e19431

Browse files
author
wonder
committed
The wkb->geos conversion may fail for some reasons so it's necessary to check the result of it.
This avoids some possible segfaults with invalid geometries. Contributed by Vita Cizek. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11116 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 99c50f2 commit 7e19431

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/core/qgsgeometry.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ static GEOSCoordSequence *createGeosCoordSequence( const QgsPolyline& points )
259259
catch ( GEOSException &e )
260260
{
261261
Q_UNUSED( e );
262-
if ( coord )
263-
GEOSCoordSeq_destroy( coord );
262+
/*if ( coord )
263+
GEOSCoordSeq_destroy( coord );*/
264264
throw;
265265
}
266266
}
@@ -335,8 +335,9 @@ static GEOSGeometry *createGeosLinearRing( const QgsPolyline& polyline )
335335
catch ( GEOSException &e )
336336
{
337337
Q_UNUSED( e );
338+
/* as MH has noticed ^, this crashes geos
338339
if ( coord )
339-
GEOSCoordSeq_destroy( coord );
340+
GEOSCoordSeq_destroy( coord );*/
340341
return 0;
341342
}
342343
}
@@ -2349,7 +2350,8 @@ double QgsGeometry::closestVertexWithContext( const QgsPoint& point, int& atVert
23492350
int closestVertexIndex = 0;
23502351

23512352
// set up the GEOS geometry
2352-
exportWkbToGeos();
2353+
if ( !exportWkbToGeos() )
2354+
return -1;
23532355

23542356
const GEOSGeometry *g = GEOSGetExteriorRing( mGeos );
23552357
if ( g == NULL )
@@ -2628,7 +2630,8 @@ int QgsGeometry::addRing( const QList<QgsPoint>& ring )
26282630

26292631
//create geos geometry from wkb if not already there
26302632
if ( !mGeos || mDirtyGeos )
2631-
exportWkbToGeos();
2633+
if ( !exportWkbToGeos() )
2634+
return 6;
26322635

26332636
int type = GEOSGeomTypeId( mGeos );
26342637

@@ -2831,7 +2834,8 @@ int QgsGeometry::addIsland( const QList<QgsPoint>& ring )
28312834
//create geos geometry from wkb if not already there
28322835
if ( !mGeos || mDirtyGeos )
28332836
{
2834-
exportWkbToGeos();
2837+
if ( !exportWkbToGeos() )
2838+
return 4;
28352839
}
28362840

28372841
if ( GEOSGeomTypeId( mGeos ) != GEOS_MULTIPOLYGON )
@@ -3164,7 +3168,8 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
31643168
}
31653169
if ( !mGeos || mDirtyGeos )
31663170
{
3167-
exportWkbToGeos();
3171+
if ( !exportWkbToGeos() )
3172+
return 1;
31683173
}
31693174

31703175
//make sure splitLine is valid
@@ -3917,6 +3922,7 @@ bool QgsGeometry::exportWkbToGeos()
39173922
mGeos = 0;
39183923
}
39193924

3925+
// this probably shouldn't return TRUE
39203926
if ( !mGeometry )
39213927
{
39223928
// no WKB => no GEOS
@@ -4768,7 +4774,8 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry
47684774

47694775
if ( !mGeos || mDirtyGeos )
47704776
{
4771-
exportWkbToGeos();
4777+
if ( !exportWkbToGeos() )
4778+
return 5;
47724779
}
47734780

47744781
//first test if linestring intersects geometry. If not, return straight away
@@ -4844,7 +4851,8 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr
48444851

48454852
if ( !mGeos || mDirtyGeos )
48464853
{
4847-
exportWkbToGeos();
4854+
if ( !exportWkbToGeos() )
4855+
return 5;
48484856
}
48494857

48504858
//first test if linestring intersects geometry. If not, return straight away
@@ -5062,7 +5070,8 @@ int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitRes
50625070
{
50635071
if ( !mGeos || mDirtyGeos )
50645072
{
5065-
exportWkbToGeos();
5073+
if ( !exportWkbToGeos() )
5074+
return 1;
50665075
}
50675076

50685077
//convert mGeos to geometry collection
@@ -5328,6 +5337,9 @@ double QgsGeometry::distance( QgsGeometry& geom )
53285337
geom.exportWkbToGeos();
53295338
}
53305339

5340+
if ( mGeos == NULL || geom.mGeos == NULL)
5341+
return -1.0;
5342+
53315343
double dist = -1.0;
53325344

53335345
try

0 commit comments

Comments
 (0)