Skip to content

Commit 18744b4

Browse files
committedNov 10, 2015
Fix crash with malformed WKT
1 parent 0853076 commit 18744b4

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
 

‎src/core/geometry/qgscurvepolygonv2.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ bool QgsCurvePolygonV2::fromWkt( const QString& wkt )
173173
}
174174
}
175175

176+
if ( mInteriorRings.isEmpty() )
177+
{
178+
clear();
179+
return false;
180+
}
181+
176182
mExteriorRing = mInteriorRings.first();
177183
mInteriorRings.removeFirst();
178184

‎tests/src/python/test_qgsgeometry.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ def testReferenceGeometry(self):
129129

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

134138
#test exporting to WKT results in expected string
135139
result = geom.exportToWkt()

‎tests/testdata/geom_data.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
9797
PointM( 4 5 6 ),PointM ( 4 5 6 ),1,0,0,0,1,0,0,POINT(4 5),4,5,4,5,
9898
PointZ (1 2 3),POINT Z (1 2 3),1,0,0,0,1,0,0,POINT(1 2),1,2,1,2,
9999
PointZM( 7 8 9 10 ),PointZM( 7 8 9 10 ),1,0,0,0,1,0,0,POINT( 7 8 ),7,8,7,8,
100+
Polygon(),,,,,,,,,,,,,,Malformed WKT
101+
Polygon,,,,,,,,,,,,,,Malformed WKT
100102
"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,
101103
"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,
102104
"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,

0 commit comments

Comments
 (0)
Please sign in to comment.