Skip to content
Permalink
Browse files

[GML parser/WFS provider] Fix crash when typename and geometry field …

…name are identical (fixes #15942)
  • Loading branch information
rouault committed Nov 11, 2017
1 parent bcb815b commit 66518eb9ee609042de02f175a2f8e1b47ae22bc8
Showing with 51 additions and 1 deletion.
  1. +4 −1 src/core/qgsgml.cpp
  2. +47 −0 tests/src/core/testqgsgml.cpp
@@ -543,7 +543,9 @@ void QgsGmlStreamingParser::startElement( const XML_Char *el, const XML_Char **a
}
}
}
else if ( localNameLen == static_cast<int>( mGeometryAttributeUTF8Len ) &&
else if ( ( parseMode == Feature || parseMode == FeatureTuple ) &&
mCurrentFeature &&
localNameLen == static_cast<int>( mGeometryAttributeUTF8Len ) &&
memcmp( pszLocalName, mGeometryAttributePtr, localNameLen ) == 0 )
{
mParseModeStack.push( QgsGmlStreamingParser::Geometry );
@@ -887,6 +889,7 @@ void QgsGmlStreamingParser::endElement( const XML_Char *el )
{
g.transform( QTransform( 0, 1, 1, 0, 0, 0 ) );
}
Q_ASSERT( mCurrentFeature );
mCurrentFeature->setGeometry( g );
}
}
@@ -78,6 +78,7 @@ class TestQgsGML : public QObject
void testThroughOGRGeometry();
void testThroughOGRGeometry_urn_EPSG_4326();
void testAccents();
void testSameTypeameAsGeomName();
};

const QString data1( "<myns:FeatureCollection "
@@ -1153,5 +1154,51 @@ void TestQgsGML::testAccents()
delete features[0].first;
}

void TestQgsGML::testSameTypeameAsGeomName()
{
QgsFields fields;
QgsGmlStreamingParser gmlParser( QStringLiteral( "foo" ), QStringLiteral( "foo" ), fields );
QCOMPARE( gmlParser.processData( QByteArray( "<myns:FeatureCollection "
"xmlns:myns='http://myns' "
"xmlns:gml='http://www.opengis.net/gml'>"
"<gml:featureMember>"
"<myns:foo fid='foo.1'>"
"<myns:foo>"
"<gml:MultiSurface srsName='EPSG:27700'>"
"<gml:surfaceMember>"
"<gml:Polygon srsName='EPSG:27700'>"
"<gml:exterior>"
"<gml:LinearRing>"
"<gml:posList>0 0 0 10 10 10 10 0 0 0</gml:posList>"
"</gml:LinearRing>"
"</gml:exterior>"
"</gml:Polygon>"
"</gml:surfaceMember>"
"<gml:surfaceMember>"
"<gml:Polygon srsName='EPSG:27700'>"
"<gml:exterior>"
"<gml:LinearRing>"
"<gml:posList>0 0 0 10 10 10 10 0 0 0</gml:posList>"
"</gml:LinearRing>"
"</gml:exterior>"
"</gml:Polygon>"
"</gml:surfaceMember>"
"</gml:MultiSurface>"
"</myns:foo>"
"</myns:foo>"
"</gml:featureMember>"
"</myns:FeatureCollection>" ), true ), true );
QCOMPARE( gmlParser.wkbType(), QgsWkbTypes::MultiPolygon );
QVector<QgsGmlStreamingParser::QgsGmlFeaturePtrGmlIdPair> features = gmlParser.getAndStealReadyFeatures();
QCOMPARE( features.size(), 1 );
QVERIFY( features[0].first->hasGeometry() );
QCOMPARE( features[0].first->geometry().wkbType(), QgsWkbTypes::MultiPolygon );
QgsMultiPolygonXY multi = features[0].first->geometry().asMultiPolygon();
QCOMPARE( multi.size(), 2 );
QCOMPARE( multi[0].size(), 1 );
QCOMPARE( multi[0][0].size(), 5 );
delete features[0].first;
}

QGSTEST_MAIN( TestQgsGML )
#include "testqgsgml.moc"

0 comments on commit 66518eb

Please sign in to comment.
You can’t perform that action at this time.