Skip to content
Permalink
Browse files
Merge pull request #2748 from jef-n/wkb-bounds-check
port more WKB parsing to Qgs(Const)WkbPtr including bounds checking
  • Loading branch information
jef-n committed Feb 9, 2016
2 parents ded1ebb + d05c31e commit b9726d7285733c27d42456c115e28d5a37f3e0be
Show file tree
Hide file tree
Showing 65 changed files with 715 additions and 903 deletions.
@@ -324,3 +324,4 @@
%Include geometry/qgspolygonv2.sip
%Include geometry/qgssurfacev2.sip
%Include geometry/qgswkbtypes.sip
%Include geometry/qgswkbptr.sip
@@ -127,7 +127,7 @@ class QgsAbstractGeometryV2
/** Sets the geometry from a WKB string.
* @see fromWkt
*/
virtual bool fromWkb( const unsigned char * wkb ) = 0;
virtual bool fromWkb( QgsConstWkbPtr wkb ) = 0;

/** Sets the geometry from a WKT string.
* @see fromWkb
@@ -368,15 +368,4 @@ class QgsAbstractGeometryV2
/** Updates the geometry type based on whether sub geometries contain z or m values.
*/
void setZMTypeFromSubGeometry( const QgsAbstractGeometryV2* subggeom, QgsWKBTypes::Type baseGeomType );

/** Reads a WKB header and tests its validity.
* @param wkbPtr
* @param wkbType destination for WKB type from header
* @param endianSwap will be set to true if endian from WKB must be swapped to match QGIS platform endianness
* @param expectedType expected WKB type
* @returns true if header is valid and matches expected type
* @note not available in Python bindings
*/
//static bool readWkbHeader( QgsConstWkbPtr& wkbPtr, QgsWKBTypes::Type& wkbType, bool& endianSwap, QgsWKBTypes::Type expectedType );

};
@@ -18,7 +18,7 @@ class QgsCircularStringV2: public QgsCurveV2

virtual QgsRectangle calculateBoundingBox() const;

virtual bool fromWkb( const unsigned char * wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -20,7 +20,7 @@ class QgsCompoundCurveV2: public QgsCurveV2

virtual QgsRectangle calculateBoundingBox() const;

virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -17,7 +17,7 @@ class QgsCurvePolygonV2: public QgsSurfaceV2


virtual QgsRectangle calculateBoundingBox() const;
virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -57,7 +57,7 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2

virtual void draw( QPainter& p ) const;

bool fromWkb( const unsigned char * wkb );
bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );
int wkbSize() const;
unsigned char* asWkb( int& binarySize ) const;
@@ -112,7 +112,8 @@ class QgsLineStringV2: public QgsCurveV2
virtual int dimension() const;
virtual QgsLineStringV2* clone() const /Factory/;

virtual bool fromWkb( const unsigned char* wkb );

virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );

int wkbSize() const;
@@ -143,7 +143,7 @@ class QgsPointV2: public QgsAbstractGeometryV2
virtual int dimension() const;
virtual QgsPointV2* clone() const /Factory/;
void clear();
virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );
virtual bool fromWkt( const QString& wkt );
int wkbSize() const;
unsigned char* asWkb( int& binarySize ) const;
@@ -13,7 +13,7 @@ class QgsPolygonV2: public QgsCurvePolygonV2
virtual QString geometryType() const;
virtual QgsPolygonV2* clone() const;

virtual bool fromWkb( const unsigned char* wkb );
virtual bool fromWkb( QgsConstWkbPtr wkb );

// inherited: bool fromWkt( const QString &wkt );

@@ -0,0 +1,21 @@
class QgsWkbPtr
{
%TypeHeaderCode
#include <qgswkbptr.h>
%End

public:
QgsWkbPtr( unsigned char *wkb /Array/, int size /ArraySize/ );

};

class QgsConstWkbPtr
{
%TypeHeaderCode
#include <qgswkbptr.h>
%End

public:
QgsConstWkbPtr( unsigned char *wkb /Array/, int size /ArraySize/ );

};
@@ -56,5 +56,5 @@ class QgsClipper
@param wkb pointer to the start of the line wkb
@param clipExtent clipping bounds
@param line out: clipped line coordinates*/
static const unsigned char* clippedLineWKB( const unsigned char* wkb, const QgsRectangle& clipExtent, QPolygonF& line );
static QgsConstWkbPtr clippedLineWKB( QgsConstWkbPtr wkb, const QgsRectangle& clipExtent, QPolygonF& line );
};
@@ -374,9 +374,9 @@ class QgsFeatureRendererV2
//! render editing vertex marker for a polygon
void renderVertexMarkerPolygon( QPolygonF& pts, QList<QPolygonF>* rings, QgsRenderContext& context );

static const unsigned char* _getPoint( QPointF& pt, QgsRenderContext& context, const unsigned char* wkb );
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
static QgsConstWkbPtr _getPoint( QPointF& pt, QgsRenderContext& context, QgsConstWkbPtr wkb );
static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );
static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );

void setScaleMethodToSymbol( QgsSymbolV2* symbol, int scaleMethod );

@@ -226,13 +226,13 @@ class QgsSymbolV2
* Creates a line string in screen coordinates from a wkb string in map
* coordinates
*/
static const unsigned char* _getLineString( QPolygonF& pts, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
static QgsConstWkbPtr _getLineString( QPolygonF& pts, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );

/**
* Creates a polygon in screen coordinates from a wkb string in map
* coordinates
*/
static const unsigned char* _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, const unsigned char* wkb, bool clipToExtent = true );
static QgsConstWkbPtr _getPolygon( QPolygonF& pts, QList<QPolygonF>& holes, QgsRenderContext& context, QgsConstWkbPtr wkb, bool clipToExtent = true );

/**
* Retrieve a cloned list of all layers that make up this symbol.
@@ -108,7 +108,8 @@ int QgsInterpolator::addVerticesToCache( const QgsGeometry *geom, bool zCoord, d
return 1;

bool hasZValue = false;
QgsConstWkbPtr currentWkbPtr( geom->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr currentWkbPtr( geom->asWkb(), geom->wkbSize() );
currentWkbPtr.readHeader();
vertexData theVertex; //the current vertex

QGis::WkbType wkbType = geom->wkbType();
@@ -199,7 +199,8 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
//parse WKB. It is ugly, but we cannot use the methods with QgsPoint because they don't contain z-values for 25D types
bool hasZValue = false;
double x, y, z;
QgsConstWkbPtr currentWkbPtr( g->asWkb() + 1 + sizeof( int ) );
QgsConstWkbPtr currentWkbPtr( g->asWkb(), g->wkbSize() );
currentWkbPtr.readHeader();
//maybe a structure or break line
Line3D* line = nullptr;

@@ -236,7 +237,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
currentWkbPtr >> nPoints;
for ( int index = 0; index < nPoints; ++index )
{
currentWkbPtr += 1 + sizeof( int );
currentWkbPtr.readHeader();
currentWkbPtr >> x >> y;
if ( hasZValue ) //skip z-coordinate for 25D geometries
{
@@ -388,7 +389,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
currentWkbPtr >> nPolys;
for ( int index = 0; index < nPolys; ++index )
{
currentWkbPtr += 1 + sizeof( int );
currentWkbPtr.readHeader();
int nRings;
currentWkbPtr >> nRings;
for ( int index2 = 0; index2 < nRings; ++index2 )

0 comments on commit b9726d7

Please sign in to comment.