Opened 10 years ago

Closed 10 years ago

#5302 closed defect (fixed)

Passing None to ogr.CreateGeometryFromWkt in python sometimes crashes

Reported by: Kurt Schwehr Owned by: hobu
Priority: normal Milestone: 1.10.2
Component: SWIG (all bindings) Version: 1.10.1
Severity: normal Keywords:
Cc:

Description

With gdal 1.10.0, we are sometimes seeing a segfault on linux and python 2.7, when doing this call. We have wrapped the call in a check to make sure that if the value was going to be None, we skip the call, but it appears that there is some unsafe handling of strings when a None could get put into the kwargs. This only happens in our test environment where I can't get easily get a debugger onto the this.

  ogr.CreateGeometryFromWkt(None)

I took a look at source:trunk/gdal/swig/include/ogr.i#L1700 where CreateGeometryFromWkt is defined for swig and at the derived code and am not sure how it is all supposed to work.

osgeo/ogr.py created by swig 1.3.40

def CreateGeometryFromWkt(*args, **kwargs):
  """CreateGeometryFromWkt(char val, SpatialReference reference = None) -> Geometry"""
  return _ogr.CreateGeometryFromWkt(*args, **kwargs)

and ogr_wrap.cpp by swig 1.3.40:

OGRGeometryShadow* CreateGeometryFromWkt( char **val, 
                                      OSRSpatialReferenceShadow *reference=NULL ) {
    OGRGeometryH geom = NULL;
    OGRErr err = OGR_G_CreateFromWkt(val,
                                      reference,
                                      &geom);
    if (err != 0 ) {
       CPLError(CE_Failure, err, "%s", OGRErrMessages(err));
       return NULL;
    }
    return (OGRGeometryShadow*) geom;
  }

I'm not sure yet what gets passed in when python uses a None.

Would switching to swig 2.0.4 or 2.0.10 possibly handle this better?

Change History (1)

comment:1 by Even Rouault, 10 years ago

Milestone: 1.10.2
Resolution: fixed
Status: newclosed

trunk r26644 and branches/1.10 26645 "Python bindings: make ogr.CreateGeometryFromWkt() and SpatialReference.ImportFromWkt() propery validate their argument (#5302)"

Note: See TracTickets for help on using tickets.