Skip to content

Commit

Permalink
Fix crash with malformed WKT
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 10, 2015
1 parent 0853076 commit 18744b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/core/geometry/qgscurvepolygonv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ bool QgsCurvePolygonV2::fromWkt( const QString& wkt )
}
}

if ( mInteriorRings.isEmpty() )
{
clear();
return false;
}

mExteriorRing = mInteriorRings.first();
mInteriorRings.removeFirst();

Expand Down
6 changes: 5 additions & 1 deletion tests/src/python/test_qgsgeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ def testReferenceGeometry(self):

#test that geometry can be created from WKT
geom = QgsGeometry.fromWkt(row['wkt'])
assert geom, "WKT conversion {} failed: could not create geom:\n{}\n".format(i + 1, row['wkt'])
if row['valid_wkt']:
assert geom, "WKT conversion {} failed: could not create geom:\n{}\n".format(i + 1, row['wkt'])
else:
assert not geom, "Corrupt WKT {} was incorrectly converted to geometry:\n{}\n".format(i + 1, row['wkt'])
continue

#test exporting to WKT results in expected string
result = geom.exportToWkt()
Expand Down
2 changes: 2 additions & 0 deletions tests/testdata/geom_data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Point( 1 2 3 4 ),PointZM( 1 2 3 4 ),1,0,0,0,1,0,0,Point( 1 2 ),1,2,1,2,"4d coord
PointM( 4 5 6 ),PointM ( 4 5 6 ),1,0,0,0,1,0,0,POINT(4 5),4,5,4,5,
PointZ (1 2 3),POINT Z (1 2 3),1,0,0,0,1,0,0,POINT(1 2),1,2,1,2,
PointZM( 7 8 9 10 ),PointZM( 7 8 9 10 ),1,0,0,0,1,0,0,POINT( 7 8 ),7,8,7,8,
Polygon(),,,,,,,,,,,,,,Malformed WKT
Polygon,,,,,,,,,,,,,,Malformed WKT
"Polygon ((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 7 5, 7 7 , 5 7, 5 5),(1 1,2 1, 2 2, 1 2, 1 1))","POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5),(1 1,2 1,2 2,1 2,1 1))",15,0,95,52,1,2,0,POINT(4.99473684210526 4.99473684210526),0,0,10,10,
"Polygon ((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 7 5, 7 7 , 5 7, 5 5))","POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))",10,0,96,48,1,1,0,POINT(4.95833333333333 4.95833333333333),0,0,10,10,
"Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))","POLYGON((0 0,10 0,10 10,0 10,0 0))",5,0,100,40,1,0,0,POINT(5 5),0,0,10,10,
Expand Down

0 comments on commit 18744b4

Please sign in to comment.