Skip to content
Permalink
Browse files

Try to fix crash on GEOS 3.8.1 when empty coordinate sequence is retu…

…rned

for a point geometry

Fixes #35719, fixes #35526

(cherry picked from commit 774f1db)
  • Loading branch information
nyalldawson committed Apr 29, 2020
1 parent ac4dc39 commit c27dcf4aa4457d316b3b1d1388bb0ce5bbd76cbe
Showing with 11 additions and 2 deletions.
  1. +7 −2 src/core/geometry/qgsgeos.cpp
  2. +4 −0 tests/src/python/test_qgsgeometry.py
@@ -1095,7 +1095,9 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeos::fromGeos( const GEOSGeometry *geos
case GEOS_POINT: // a point
{
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, geos );
return std::unique_ptr<QgsAbstractGeometry>( coordSeqPoint( cs, 0, hasZ, hasM ).clone() );
unsigned int nPoints = 0;
GEOSCoordSeq_getSize_r( geosinit()->ctxt, cs, &nPoints );
return nPoints > 0 ? std::unique_ptr<QgsAbstractGeometry>( coordSeqPoint( cs, 0, hasZ, hasM ).clone() ) : nullptr;
}
case GEOS_LINESTRING:
{
@@ -1115,7 +1117,10 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeos::fromGeos( const GEOSGeometry *geos
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit.ctxt, GEOSGetGeometryN_r( geosinit.ctxt, geos, i ) );
if ( cs )
{
multiPoint->addGeometry( coordSeqPoint( cs, 0, hasZ, hasM ).clone() );
unsigned int nPoints = 0;
GEOSCoordSeq_getSize_r( geosinit()->ctxt, cs, &nPoints );
if ( nPoints > 0 )
multiPoint->addGeometry( coordSeqPoint( cs, 0, hasZ, hasM ).clone() );
}
}
return std::move( multiPoint );
@@ -5362,6 +5362,10 @@ def testLineStringFromQPolygonF(self):
line = QgsLineString.fromQPolygonF(QPolygonF([QPointF(1.5, 2.5), QPointF(3, 4), QPointF(3, 6.5), QPointF(1.5, 2.5)]))
self.assertEqual(line.asWkt(1), 'LineString (1.5 2.5, 3 4, 3 6.5, 1.5 2.5)')

def testGeosCrash(self):
# test we don't crash when geos returns a point geometry with no points
QgsGeometry.fromWkt('Polygon ((0 0, 1 1, 1 0, 0 0))').intersection(QgsGeometry.fromWkt('Point (42 0)')).isNull()

def renderGeometry(self, geom, use_pen, as_polygon=False, as_painter_path=False):
image = QImage(200, 200, QImage.Format_RGB32)
image.fill(QColor(0, 0, 0))

0 comments on commit c27dcf4

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