Skip to content

Commit e8be21a

Browse files
Sandro Santillijef-n
Sandro Santilli
authored andcommitted
Add test for premature WKB end in QgsGeometry::asWkt
See #14182
1 parent 2ea3d77 commit e8be21a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/src/core/testqgsgeometry.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class TestQgsGeometry : public QObject
9191

9292
void exportToGeoJSON();
9393

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

106+
// Release return with delete []
107+
unsigned char * hex2bytes( const char *hex, int *size )
108+
{
109+
QByteArray ba = QByteArray::fromHex( hex );
110+
unsigned char *out = new unsigned char[ba.size()];
111+
memcpy( out, ba.data(), ba.size() );
112+
*size = ba.size();
113+
return out;
114+
}
115+
116+
QString bytes2hex( const unsigned char *bytes, int size )
117+
{
118+
QByteArray ba(( const char * )bytes, size );
119+
QString out = ba.toHex();
120+
return out;
121+
}
122+
123+
104124
QString elemToString( const QDomElement& elem ) const;
105125

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

3388+
void TestQgsGeometry::wkbInOut()
3389+
{
3390+
// Premature end of WKB
3391+
// See http://hub.qgis.org/issues/14182
3392+
const char *hexwkb = "0102000000EF0000000000000000000000000000000000000000000000000000000000000000000000";
3393+
int size;
3394+
unsigned char *wkb = hex2bytes( hexwkb, &size );
3395+
QgsGeometry g14182;
3396+
// NOTE: wkb onwership transferred to QgsGeometry
3397+
g14182.fromWkb( wkb, size );
3398+
//QList<QgsGeometry::Error> errors;
3399+
//g14182.validateGeometry(errors);
3400+
// Check with valgrind !
3401+
QString wkt = g14182.exportToWkt();
3402+
QCOMPARE( wkt, QString() );
3403+
3404+
}
3405+
33683406
QTEST_MAIN( TestQgsGeometry )
33693407
#include "testqgsgeometry.moc"

0 commit comments

Comments
 (0)