Skip to content
Permalink
Browse files

Fix potential crash while creating geometry from WKB with bad header

  • Loading branch information
nyalldawson committed May 1, 2016
1 parent 752ba70 commit 1f032aa563cd3d081cdd77376c339c3b699a14c3
Showing with 19 additions and 1 deletion.
  1. +11 −1 src/core/geometry/qgsgeometryfactory.cpp
  2. +8 −0 tests/src/core/testqgsgeometry.cpp
@@ -36,7 +36,17 @@ QgsAbstractGeometryV2* QgsGeometryFactory::geomFromWkb( QgsConstWkbPtr wkbPtr )
return nullptr;

//find out type (bytes 2-5)
QgsWKBTypes::Type type = wkbPtr.readHeader();
QgsWKBTypes::Type type = QgsWKBTypes::Unknown;
try
{
type = wkbPtr.readHeader();
}
catch ( const QgsWkbException &e )
{
Q_UNUSED( e );
QgsDebugMsg( "WKB exception while reading header: " + e.what() );
return nullptr;
}
wkbPtr -= 1 + sizeof( int );

QgsAbstractGeometryV2* geom = nullptr;
@@ -3409,6 +3409,14 @@ void TestQgsGeometry::wkbInOut()
QString wkt = g14182.exportToWkt();
QCOMPARE( wkt, QString() );

//WKB with a truncated header
const char *badHeaderHexwkb = "0102";
wkb = hex2bytes( badHeaderHexwkb, &size );
QgsGeometry badHeader;
// NOTE: wkb onwership transferred to QgsGeometry
badHeader.fromWkb( wkb, size );
QVERIFY( badHeader.isEmpty() );
QCOMPARE( badHeader.wkbType(), QGis::WKBUnknown );
}

QTEST_MAIN( TestQgsGeometry )

0 comments on commit 1f032aa

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