Skip to content

Commit

Permalink
mappostgis.cpp: fix Untrusted loop bound (CID 1503262)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed May 23, 2021
1 parent d69e866 commit 00114ba
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mappostgis.cpp
Expand Up @@ -315,6 +315,8 @@ wkbReadLine(wkbObj *w, lineObj *line, int nZMFlag)
{
pointObj p;
const int npoints = wkbReadInt(w);
if( npoints > (int)((w->size - (w->ptr - w->wkb)) / 16) )
return;

line->numpoints = npoints;
line->point =(pointObj*) msSmallMalloc(npoints * sizeof(pointObj));
Expand Down Expand Up @@ -364,6 +366,8 @@ wkbSkipGeometry(wkbObj *w)
case WKB_MULTICURVE:
case WKB_MULTISURFACE: {
const int ngeoms = wkbReadInt(w);
if( ngeoms > (int)((w->size - (w->ptr - w->wkb)) / 4) )
return;
for ( int i = 0; i < ngeoms; i++ ) {
wkbSkipGeometry(w);
}
Expand Down Expand Up @@ -426,6 +430,8 @@ wkbConvPolygonToShape(wkbObj *w, shapeObj *shape)

/* How many rings? */
const int nrings = wkbReadInt(w);
if( nrings > (int)((w->size - (w->ptr - w->wkb)) / 4) )
return MS_FAILURE;

/* Add each ring to the shape */
lineObj line;
Expand All @@ -450,10 +456,12 @@ wkbConvCurvePolygonToShape(wkbObj *w, shapeObj *shape)
/*endian = */wkbReadChar(w);
int nZMFlag;
const int type = wkbTypeMap(w,wkbReadInt(w), &nZMFlag);
const int ncomponents = wkbReadInt(w);

if( type != WKB_CURVEPOLYGON ) return MS_FAILURE;

const int ncomponents = wkbReadInt(w);
if( ncomponents > (int)((w->size - (w->ptr - w->wkb)) / 4) )
return MS_FAILURE;

/* Lower the allowed dimensionality so we can
* catch the linear ring components */
shape->type = MS_SHAPE_LINE;
Expand Down Expand Up @@ -526,6 +534,8 @@ wkbConvCompoundCurveToShape(wkbObj *w, shapeObj *shape)

/* How many components in the compound curve? */
const int ncomponents = wkbReadInt(w);
if( ncomponents > (int)((w->size - (w->ptr - w->wkb)) / 4) )
return MS_FAILURE;

/* We'll load each component onto a line in a shape */
for( int i = 0; i < ncomponents; i++ )
Expand Down

0 comments on commit 00114ba

Please sign in to comment.