Skip to content

Commit 35ba4b3

Browse files
committedOct 6, 2016
Fix crash when validating geometry (fix #15660)
Also fix python bindings for QgsGeometryValidator (cherry-picked from bc32b1f)
1 parent 683309a commit 35ba4b3

File tree

4 files changed

+95
-3
lines changed

4 files changed

+95
-3
lines changed
 

‎python/core/qgsgeometryvalidator.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class QgsGeometryValidator : QThread
1313
void stop();
1414

1515
/** Validate geometry and produce a list of geometry errors */
16-
static void validateGeometry( const QgsGeometry *g, QList<QgsGeometry::Error> &errors );
16+
static void validateGeometry( const QgsGeometry *g, QList<QgsGeometry::Error> &errors /Out/ );
1717

1818
signals:
1919
void errorFound( const QgsGeometry::Error& );

‎src/core/qgsgeometryvalidator.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,31 @@ void QgsGeometryValidator::validatePolyline( int i, QgsPolyline line, bool ring
147147
if ( !intersectLines( line[j], v, line[k], w, s ) )
148148
continue;
149149

150-
double d = -distLine2Point( line[j], v.perpVector(), s );
150+
double d = 0.0;
151+
try
152+
{
153+
d = -distLine2Point( line[j], v.perpVector(), s );
154+
}
155+
catch ( QgsException & e )
156+
{
157+
Q_UNUSED( e );
158+
QgsDebugMsg( "Error validating: " + e.what() );
159+
continue;
160+
}
151161
if ( d < 0 || d > vl )
152162
continue;
153163

154-
d = -distLine2Point( line[k], w.perpVector(), s );
164+
try
165+
{
166+
d = -distLine2Point( line[k], w.perpVector(), s );
167+
}
168+
catch ( QgsException & e )
169+
{
170+
Q_UNUSED( e );
171+
QgsDebugMsg( "Error validating: " + e.what() );
172+
continue;
173+
}
174+
155175
if ( d <= 0 || d >= w.length() )
156176
continue;
157177

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ ADD_PYTHON_TEST(PyQgsFontUtils test_qgsfontutils.py)
4242
ADD_PYTHON_TEST(PyQgsGeometryAvoidIntersections test_qgsgeometry_avoid_intersections.py)
4343
ADD_PYTHON_TEST(PyQgsGeometryGeneratorSymbolLayerV2 test_qgsgeometrygeneratorsymbollayerv2.py)
4444
ADD_PYTHON_TEST(PyQgsGeometryTest test_qgsgeometry.py)
45+
ADD_PYTHON_TEST(PyQgsGeometryValidator test_qgsgeometryvalidator.py)
4546
ADD_PYTHON_TEST(PyQgsGraduatedSymbolRendererV2 test_qgsgraduatedsymbolrendererv2.py)
4647
ADD_PYTHON_TEST(PyQgsMapUnitScale test_qgsmapunitscale.py)
4748
ADD_PYTHON_TEST(PyQgsMemoryProvider test_provider_memory.py)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsGeometryValidator.
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Nyall Dawson'
10+
__date__ = '03/10/2016'
11+
__copyright__ = 'Copyright 2016, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import os
16+
import csv
17+
import math
18+
19+
from qgis.core import (
20+
QgsGeometry,
21+
QgsGeometryValidator
22+
)
23+
24+
from qgis.testing import (
25+
unittest
26+
)
27+
28+
29+
class TestQgsGeometryValidator(unittest.TestCase):
30+
31+
def testIssue15660(self):
32+
""" Test crash when validating geometry (#15660) """
33+
g = QgsGeometry.fromWkt(
34+
"Polygon ((0.44256348235389709 -47.87645625696347906, -2.88231630340906797 -47.90003919913998232,"
35+
"-2.88589842578005751 -48.91215450743293047, -2.8858984257800584 -48.91215450743293047,"
36+
"-2.88589842578005751 -48.91215450743292337, -2.88589842632776516 -48.9121545074024624,"
37+
"-3.24858148608664266 -48.89198543875494352, -3.27689849271356159 -49.40119850743292318,"
38+
"-4.37689842578006072 -49.40119850743292318, -4.3768984257800625 -49.40119850743293739,"
39+
"-6.11689842578005738 -49.40119850743293739, -6.11689842578006093 -49.40119850743292318,"
40+
"-7.03689842578006086 -49.40119850743292318, -7.02239489567359776 -48.93302358132471852,"
41+
"-7.02177188091450688 -48.91291272055079276, -7.02177188393206286 -48.91291272045731375,"
42+
"-7.02141642578006309 -48.9014385074329212, -7.7002102410998674 -48.88041051649613422,"
43+
"-7.70077301577442341 -48.89187793078160382, -7.70077301577442341 -48.89187793078160382,"
44+
"-7.70233865095334291 -48.92378019651650334, -7.72576842578006051 -49.40119850743292318,"
45+
"-9.26576842578005966 -49.40119850743292318, -9.26576842578006321 -49.40119850743293739,"
46+
"-13.28076842578006023 -49.40119850743293739, -13.04700849136197149 -44.82717853953759857,"
47+
"-12.22739168108193297 -44.85224022031006541, -12.22501286465108805 -44.774446133668377,"
48+
"-12.22288921611744783 -44.774511069530881, -12.2155540445085915 -44.53462318893357264,"
49+
"-13.0310217329353506 -44.50968822589503304, -12.87640859053235687 -41.29089836691012749,"
50+
"-7.83390711693117936 -41.74840291007100745, -7.88211379129075596 -42.99075321817508666,"
51+
"-7.43245210877673657 -43.00820115628285123, -7.50410812906098013 -44.67868742523263847,"
52+
"-7.52086717830689011 -44.67817497540850979, -7.52820234991574644 -44.91806285600581816,"
53+
"-7.51439432253991058 -44.91848507095944854, -7.57421591980290287 -46.3130804785479242,"
54+
"-8.32385639731993621 -46.28985691678211367, -8.44985043007881842 -48.85718773355701217,"
55+
"-6.26478736265246283 -48.92487774800262912, -6.18500945357052245 -46.35611749220839073,"
56+
"-6.94163842159974198 -46.33267751510010157, -6.82382190915497944 -40.77447960826383166,"
57+
"-5.48772831582523146 -40.77837853452808758, -5.48973219643841759 -39.92687558952010107,"
58+
"-2.75658441771447116 -40.04490036239724304, -3.1241861109063862 -46.6551270968877958,"
59+
"-2.78977790434136885 -46.6737244011090695, -2.78977790434136796 -46.6737244011090695,"
60+
"-2.71083842578005996 -44.83541850743291945, -2.71083842578005729 -44.83541850743291945,"
61+
"-0.86779302740823816 -44.89143693883772812, -0.86745855610774569 -44.87743669555854353,"
62+
"0.29843811058281489 -44.90401226269042922, 0.20437651721061911 -46.69301920907949466,"
63+
"0.50389019278376956 -46.71008040893148916, 0.44256348235389709 -47.87645625696347906))")
64+
65+
self.assertTrue(g)
66+
# make sure validating this geometry doesn't crash QGIS
67+
QgsGeometryValidator.validateGeometry(g)
68+
69+
70+
if __name__ == '__main__':
71+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.