[geos-devel] linearref::LinearIterator segfaults

strk strk at keybit.net
Sat Jun 19 07:02:31 EDT 2010


Doing tests for the PHP biding I found a segfault
when using the C-API GEOSProject method against
something which is not a lineal geometry.

This goes down to linearref::LinearIterator assuming
the input is a lineal geometry w/out checking.

The bug goes deep into JTS as well, where you don't get
a segfault but do a wrong assumption here:

  private void loadCurrentLine()                                                  {
    if (componentIndex >= numLines) {
      currentLine = null;
      return;
    }
    currentLine = (LineString) linear.getGeometryN(componentIndex);
  }

That is, there's no code checking that 'linear' is a LINESTRING
or MULTILINESTRING:

  public LinearIterator(Geometry linear, int componentIndex, int vertexIndex) {
    this.linear = linear;
    numLines = linear.getNumGeometries();
    this.componentIndex = componentIndex;
    this.vertexIndex = vertexIndex;
    loadCurrentLine();
  }

I'd throw an IllegalArgumentException from the constructor, if geom
is not LINEAL.

Will do this in GEOS trunk, but wanted to signal JTS too...

--strk;

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html


More information about the geos-devel mailing list