Skip to content

Commit

Permalink
Fix potential crashes in geometry checker (identified by Coverity)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 28, 2017
1 parent 566d75b commit a9370af
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError *error, int method,

// Check if error still applies
int n = QgsGeometryCheckerUtils::polyLineSize( geometry, vidx.part, vidx.ring );
if ( n == 0 )
{
error->setObsolete();
return;
}
const QgsPointV2 &p1 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex - 1 + n ) % n ) );
const QgsPointV2 &p2 = geometry->vertexAt( vidx );
const QgsPointV2 &p3 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + 1 ) % n ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError *error, int

// Check if error still applies
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring );
if ( nVerts == 0 )
{
error->setObsolete();
return;
}
QgsPointV2 pi = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + nVerts - 1 ) % nVerts ) );
QgsPointV2 pj = geom->vertexAt( error->vidx() );
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) >= QgsGeometryCheckPrecision::tolerance() * QgsGeometryCheckPrecision::tolerance() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ void QgsGeometrySegmentLengthCheck::fixError( QgsGeometryCheckError *error, int

// Check if error still applies
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring );
if ( nVerts == 0 )
{
error->setObsolete();
return;
}

QgsPointV2 pi = geom->vertexAt( error->vidx() );
QgsPointV2 pj = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex - 1 + nVerts ) % nVerts ) );
double dist = qSqrt( QgsGeometryUtils::sqrDistance2D( pi, pj ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError *error, i
// Check if error still applies
bool ringIsClosed = false;
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring, &ringIsClosed );
if ( inter.segment1 >= nVerts || inter.segment2 >= nVerts )
if ( nVerts == 0 || inter.segment1 >= nVerts || inter.segment2 >= nVerts )
{
error->setObsolete();
return;
Expand Down

0 comments on commit a9370af

Please sign in to comment.