Skip to content
Permalink
Browse files

Add test for premature WKB end in QgsGeometry::asWkt

See #14182
  • Loading branch information
Sandro Santilli authored and jef-n committed Feb 1, 2016
1 parent 2ea3d77 commit e8be21ad610c44f2ffecce973c8aa23748b2d0b8
Showing with 38 additions and 0 deletions.
  1. +38 −0 tests/src/core/testqgsgeometry.cpp
@@ -91,6 +91,8 @@ class TestQgsGeometry : public QObject

void exportToGeoJSON();

void wkbInOut();

private:
/** A helper method to do a render check to see if the geometry op is as expected */
bool renderCheck( const QString& theTestName, const QString& theComment = "", int mismatchCount = 0 );
@@ -101,6 +103,24 @@ class TestQgsGeometry : public QObject
/** A helper method to dump to qdebug the geometry of a polyline */
void dumpPolyline( QgsPolyline &thePolyline );

// Release return with delete []
unsigned char * hex2bytes( const char *hex, int *size )
{
QByteArray ba = QByteArray::fromHex( hex );
unsigned char *out = new unsigned char[ba.size()];
memcpy( out, ba.data(), ba.size() );
*size = ba.size();
return out;
}

QString bytes2hex( const unsigned char *bytes, int size )
{
QByteArray ba(( const char * )bytes, size );
QString out = ba.toHex();
return out;
}


QString elemToString( const QDomElement& elem ) const;

QgsPoint mPoint1;
@@ -3365,5 +3385,23 @@ QString TestQgsGeometry::elemToString( const QDomElement& elem ) const
return s;
}

void TestQgsGeometry::wkbInOut()
{
// Premature end of WKB
// See http://hub.qgis.org/issues/14182
const char *hexwkb = "0102000000EF0000000000000000000000000000000000000000000000000000000000000000000000";
int size;
unsigned char *wkb = hex2bytes( hexwkb, &size );
QgsGeometry g14182;
// NOTE: wkb onwership transferred to QgsGeometry
g14182.fromWkb( wkb, size );
//QList<QgsGeometry::Error> errors;
//g14182.validateGeometry(errors);
// Check with valgrind !
QString wkt = g14182.exportToWkt();
QCOMPARE( wkt, QString() );

}

QTEST_MAIN( TestQgsGeometry )
#include "testqgsgeometry.moc"

0 comments on commit e8be21a

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