Skip to content

Commit cc1a34f

Browse files
committedJul 16, 2015
Guard against some crashes in geometry
1 parent daa4d6a commit cc1a34f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed
 

‎src/core/geometry/qgscircularstringv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ bool QgsCircularStringV2::insertVertex( const QgsVertexId& position, const QgsPo
695695

696696
bool QgsCircularStringV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newPos )
697697
{
698-
if ( position.vertex < 0 || position.vertex > mX.size() )
698+
if ( position.vertex < 0 || position.vertex >= mX.size() )
699699
{
700700
return false;
701701
}

‎src/core/geometry/qgslinestringv2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ bool QgsLineStringV2::insertVertex( const QgsVertexId& position, const QgsPointV
358358

359359
bool QgsLineStringV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newPos )
360360
{
361-
if ( position.vertex < 0 || position.vertex > mCoords.size() )
361+
if ( position.vertex < 0 || position.vertex >= mCoords.size() )
362362
{
363363
return false;
364364
}
@@ -378,7 +378,7 @@ bool QgsLineStringV2::moveVertex( const QgsVertexId& position, const QgsPointV2&
378378

379379
bool QgsLineStringV2::deleteVertex( const QgsVertexId& position )
380380
{
381-
if ( position.vertex > ( mCoords.size() - 1 ) || position.vertex < 0 )
381+
if ( position.vertex >= mCoords.size() || position.vertex < 0 )
382382
{
383383
return false;
384384
}

‎tests/src/python/test_qgsgeometry.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,12 @@ def testMultipoint(self):
751751

752752
def testMoveVertex(self):
753753
multipoint = QgsGeometry.fromWkt( "MultiPoint ((5 0),(0 0),(0 4),(5 4),(5 1),(1 1),(1 3),(4 3),(4 2),(2 2))" )
754+
755+
#try moving invalid vertices
756+
assert not multipoint.moveVertex( 9, 9, -1 ), "move vertex succeeded when it should have failed"
757+
assert not multipoint.moveVertex( 9, 9, 10 ), "move vertex succeeded when it should have failed"
758+
assert not multipoint.moveVertex( 9, 9, 11 ), "move vertex succeeded when it should have failed"
759+
754760
for i in range(0,10):
755761
assert multipoint.moveVertex( i+1, -1-i, i ), "move vertex %d failed" % i
756762
expwkt = "MultiPoint ((1 -1),(2 -2),(3 -3),(4 -4),(5 -5),(6 -6),(7 -7),(8 -8),(9 -9),(10 -10))"
@@ -767,6 +773,12 @@ def testMoveVertex(self):
767773
# |
768774
# 1-+-+-+-+-0 !
769775
polyline = QgsGeometry.fromWkt( "LineString (5 0, 0 0, 0 4, 5 4, 5 1, 1 1, 1 3, 4 3, 4 2, 2 2)" )
776+
777+
#try moving invalid vertices
778+
assert not polyline.moveVertex( 9, 9, -1 ), "move vertex succeeded when it should have failed"
779+
assert not polyline.moveVertex( 9, 9, 10 ), "move vertex succeeded when it should have failed"
780+
assert not polyline.moveVertex( 9, 9, 11 ), "move vertex succeeded when it should have failed"
781+
770782
assert polyline.moveVertex( 5.5, 4.5, 3 ), "move vertex failed"
771783
expwkt = "LineString (5 0, 0 0, 0 4, 5.5 4.5, 5 1, 1 1, 1 3, 4 3, 4 2, 2 2)"
772784
wkt = polyline.exportToWkt()
@@ -781,6 +793,7 @@ def testMoveVertex(self):
781793

782794
assert not polygon.moveVertex( 3, 4, -10 ), "move vertex unexpectedly succeeded"
783795
assert not polygon.moveVertex( 3, 4, 7 ), "move vertex unexpectedly succeeded"
796+
assert not polygon.moveVertex( 3, 4, 8 ), "move vertex unexpectedly succeeded"
784797

785798
assert polygon.moveVertex( 1, 2, 0 ), "move vertex failed"
786799
expwkt = "Polygon ((1 2, 1 0, 1 1, 2 1, 2 2, 0 2, 1 2))"
@@ -803,6 +816,11 @@ def testMoveVertex(self):
803816
# | | | |
804817
# 0-1 7-8
805818
polygon = QgsGeometry.fromWkt( "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))" )
819+
820+
assert not polygon.moveVertex( 3, 4, -10 ), "move vertex unexpectedly succeeded"
821+
assert not polygon.moveVertex( 3, 4, 14 ), "move vertex unexpectedly succeeded"
822+
assert not polygon.moveVertex( 3, 4, 15 ), "move vertex unexpectedly succeeded"
823+
806824
assert polygon.moveVertex( 6, 2, 9 ), "move vertex failed"
807825
expwkt = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 6 2, 3 2, 3 1, 4 1, 4 0)))"
808826
wkt = polygon.exportToWkt()

0 commit comments

Comments
 (0)
Please sign in to comment.