Skip to content

Commit

Permalink
port more WKB parsing to Qgs(Const)WkbPtr including bounds checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 9, 2016
1 parent ded1ebb commit 2ea3d77
Show file tree
Hide file tree
Showing 65 changed files with 639 additions and 895 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,4 @@
%Include geometry/qgspolygonv2.sip
%Include geometry/qgssurfacev2.sip
%Include geometry/qgswkbtypes.sip
%Include geometry/qgswkbptr.sip
13 changes: 1 addition & 12 deletions python/core/geometry/qgsabstractgeometryv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );

};
2 changes: 1 addition & 1 deletion python/core/geometry/qgscircularstringv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion python/core/geometry/qgscompoundcurvev2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion python/core/geometry/qgscurvepolygonv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion python/core/geometry/qgsgeometrycollectionv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion python/core/geometry/qgslinestringv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion python/core/geometry/qgspointv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion python/core/geometry/qgspolygonv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
21 changes: 21 additions & 0 deletions python/core/geometry/qgswkbptr.sip
Original file line number Diff line number Diff line change
@@ -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/ );

};
2 changes: 1 addition & 1 deletion python/core/qgsclipper.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};
6 changes: 3 additions & 3 deletions python/core/symbology-ng/qgsrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions python/core/symbology-ng/qgssymbolv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/interpolation/qgsinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions src/analysis/interpolation/qgstininterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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 )
Expand Down
Loading

0 comments on commit 2ea3d77

Please sign in to comment.