Opened 15 years ago

Closed 15 years ago

Last modified 11 years ago

#2792 closed defect (fixed)

Crash in get_Area()

Reported by: fbrachere Owned by: Even Rouault
Priority: normal Milestone:
Component: OGR_SF Version:
Severity: normal Keywords:
Cc:

Description

Gdal crash in OGRLinearRing::get_Area() if the linearRing contains zero point, a sample code:

int main (int argc, char **argv)
{
	OGRPolygon *poly = new OGRPolygon();
	OGRLinearRing *extRing = new OGRLinearRing();
	poly->addRing(extRing);
	double area = poly->get_Area();
	printf("Area: %f\n",area);

	return 0;
}

The problem is in the file ogrlinearring.cpp, line 431 (for gdal 1.6.0):

    dfAreaSum += 0.5 * ( paoPoints[nPointCount-1].x * paoPoints[0].y
                         - paoPoints[0].x * paoPoints[nPointCount-1].y );

We can patch like this:

    if (nPointCount)
         dfAreaSum += 0.5 * ( paoPoints[nPointCount-1].x * paoPoints[0].y
                              - paoPoints[0].x * paoPoints[nPointCount-1].y );

Change History (6)

comment:1 by warmerdam, 15 years ago

Resolution: fixed
Status: newclosed

Correction applied in trunk (r16122), 1.5 branch (r16123) and 1.6 branch (r16124).

Thanks!

comment:2 by fbrachere, 15 years ago

Resolution: fixed
Status: closedreopened

I think there is a typo mistake in your commit (you wrote nPoint instead of nPointCount)

comment:3 by Even Rouault, 15 years ago

Owner: changed from warmerdam to Even Rouault
Status: reopenednew

Right, trunk doesn't compile anymore... And I noticed that there was a similar problem with isClockWise()

comment:4 by Even Rouault, 15 years ago

Resolution: fixed
Status: newclosed

Fixed in trunk (r16125), 1.6 branch (r16126) and 1.5 branch (r16127)

comment:5 by Even Rouault, 15 years ago

Milestone: 1.6.11.5.5

comment:6 by Even Rouault, 11 years ago

Milestone: 1.5.5

Milestone 1.5.5 deleted

Note: See TracTickets for help on using tickets.