Ticket #2792 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Crash in get_Area()

Reported by: fbrachere Owned by: rouault
Priority: normal Milestone: 1.5.5
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

Changed 3 years ago by warmerdam

  • status changed from new to closed
  • resolution set to fixed

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

Thanks!

Changed 3 years ago by fbrachere

  • status changed from closed to reopened
  • resolution fixed deleted

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

Changed 3 years ago by rouault

  • owner changed from warmerdam to rouault
  • status changed from reopened to new

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

Changed 3 years ago by rouault

  • status changed from new to closed
  • resolution set to fixed

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

Changed 3 years ago by rouault

  • milestone changed from 1.6.1 to 1.5.5
Note: See TracTickets for help on using tickets.