[geos-devel] Re: linearref::LinearIterator segfaults

Martin Davis mbdavis at refractions.net
Mon Jun 21 12:06:12 EDT 2010


Thanks, strk.

I added a check in the LinearIterator constructor:

  /**
   * Creates an iterator starting at
   * a component and vertex in a linear {@link Geometry}
   *
   * @param linearGeom the linear geometry to iterate over
   * @param componentIndex the component to start at
   * @param vertexIndex the vertex to start at
   * @throws IllegalArgumentException if linearGeom is not lineal
   */
  public LinearIterator(Geometry linearGeom, int componentIndex, int 
vertexIndex)
  {
      if (! (linearGeom instanceof Lineal))
              throw new IllegalArgumentException("Lineal geometry is 
required");


strk wrote:
> 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
>   

-- 
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022



More information about the geos-devel mailing list