Skip to content

Commit c27dcf4

Browse files
committedApr 29, 2020
Try to fix crash on GEOS 3.8.1 when empty coordinate sequence is returned
for a point geometry Fixes #35719, fixes #35526 (cherry picked from commit 774f1db)
1 parent ac4dc39 commit c27dcf4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎src/core/geometry/qgsgeos.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,9 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeos::fromGeos( const GEOSGeometry *geos
10951095
case GEOS_POINT: // a point
10961096
{
10971097
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, geos );
1098-
return std::unique_ptr<QgsAbstractGeometry>( coordSeqPoint( cs, 0, hasZ, hasM ).clone() );
1098+
unsigned int nPoints = 0;
1099+
GEOSCoordSeq_getSize_r( geosinit()->ctxt, cs, &nPoints );
1100+
return nPoints > 0 ? std::unique_ptr<QgsAbstractGeometry>( coordSeqPoint( cs, 0, hasZ, hasM ).clone() ) : nullptr;
10991101
}
11001102
case GEOS_LINESTRING:
11011103
{
@@ -1115,7 +1117,10 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeos::fromGeos( const GEOSGeometry *geos
11151117
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, GEOSGetGeometryN_r( geosinit.ctxt, geos, i ) );
11161118
if ( cs )
11171119
{
1118-
multiPoint->addGeometry( coordSeqPoint( cs, 0, hasZ, hasM ).clone() );
1120+
unsigned int nPoints = 0;
1121+
GEOSCoordSeq_getSize_r( geosinit()->ctxt, cs, &nPoints );
1122+
if ( nPoints > 0 )
1123+
multiPoint->addGeometry( coordSeqPoint( cs, 0, hasZ, hasM ).clone() );
11191124
}
11201125
}
11211126
return std::move( multiPoint );

‎tests/src/python/test_qgsgeometry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5362,6 +5362,10 @@ def testLineStringFromQPolygonF(self):
53625362
line = QgsLineString.fromQPolygonF(QPolygonF([QPointF(1.5, 2.5), QPointF(3, 4), QPointF(3, 6.5), QPointF(1.5, 2.5)]))
53635363
self.assertEqual(line.asWkt(1), 'LineString (1.5 2.5, 3 4, 3 6.5, 1.5 2.5)')
53645364

5365+
def testGeosCrash(self):
5366+
# test we don't crash when geos returns a point geometry with no points
5367+
QgsGeometry.fromWkt('Polygon ((0 0, 1 1, 1 0, 0 0))').intersection(QgsGeometry.fromWkt('Point (42 0)')).isNull()
5368+
53655369
def renderGeometry(self, geom, use_pen, as_polygon=False, as_painter_path=False):
53665370
image = QImage(200, 200, QImage.Format_RGB32)
53675371
image.fill(QColor(0, 0, 0))

0 commit comments

Comments
 (0)
Please sign in to comment.