Ticket #1718 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

OSR ExportToProj4 causes a setfault with an empty reference

Reported by: hobu Owned by: warmerdam
Priority: normal Milestone: 1.4.3
Component: OGR_SRS Version: svn-trunk
Severity: normal Keywords: proj4
Cc: mloskot

Description (last modified by hobu) (diff)

import osr
ref = osr.SpatialReference()

# download some junk
ref.SetFromUserInput('http://spatialreference.org/user/6')

# no problem here
print ref.ExportToWkt()

# goes splat here
print ref.ExportToProj4()
0x024f48b9 in OGR_SRSNode::GetValue (this=0x0) at /Users/hobu/svn/gdal/ogr/ogr_spatialref.h:90
90          const char  *GetValue() const { return pszValue; }
(gdb) bt
#0  0x024f48b9 in OGR_SRSNode::GetValue (this=0x0) at /Users/hobu/svn/gdal/ogr/ogr_spatialref.h:90
#1  0x0236d764 in OGRSpatialReference::exportToProj4 (this=0x30b870, ppszProj4=0xbffff518) at ogr_srs_proj4.cpp:957
#2  0x023730e1 in OSRExportToProj4 (hSRS=0x30b870, ppszReturn=0xbffff518) at ogr_srs_proj4.cpp:919
#3  0x0020c324 in _wrap_SpatialReference_ExportToProj4 (args=0x79f50) at osr_wrap.cpp:3271
#4  0x97eb67fe in PyObject_Call ()
#5  0x97f07450 in _PyEval_SliceIndex ()
#6  0x97f08a98 in PyEval_EvalCodeEx ()
#7  0x97f06f6d in _PyEval_SliceIndex ()
#8  0x97f08a98 in PyEval_EvalCodeEx ()
#9  0x97f08bbb in PyEval_EvalCode ()
#10 0x97f21dc5 in PyErr_Display ()
#11 0x97f2395a in PyRun_SimpleFileExFlags ()
#12 0x97f2b42b in Py_Main ()
#13 0x00001f8e in start ()
Current language:  auto; currently c++

Change History

Changed 5 years ago by hobu

  • description modified (diff)

Changed 5 years ago by warmerdam

  • status changed from new to closed
  • component changed from default to OGR_SRS
  • version changed from unspecified to 1.4.0
  • milestone changed from 1.5.0 to 1.4.3
  • keywords proj4 added
  • resolution set to fixed

The problem was introduced in 1.4.0 with the EXTENSION[] mechanism. I have corrected it in 1.4 and trunk branches.

Also added an error catch for unrecognised projection strings in trunk.

Also added tests for these cases in gdalautotest/osr/osr_proj4.py.

Changed 4 years ago by mloskot

The old Python bindings still throw segmentation fault. The problem is in gdal_wrap.c:2388, OGRFree(wkt) is called for data allocated on stack (wkt = "").

Here is possible fix: {{[ err = OSRExportToProj4( _arg0, &wkt ); if( wkt == NULL ) {

ret = Py_BuildValue( "s", wkt ); OGRFree( wkt );

} else {

ret = Py_BuildValue( "s", "" );

} }}}

Changed 4 years ago by mloskot

  • cc mloskot added

Changed 4 years ago by mloskot

  • status changed from closed to reopened
  • resolution fixed deleted

Changed 4 years ago by mloskot

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

Taking this bug to apply termporary fix to gdal.i.

Changed 4 years ago by mloskot

  • status changed from new to assigned

First, I applied the fix to gdal_wrap.c first, so I was able to test it using the buildbot (r11883). Next, I fixed gdal.i (r11884) and now it's needed to regenerate gdal_wrap.c to apply the fix permanently.

Changed 4 years ago by mloskot

  • owner changed from mloskot to warmerdam
  • status changed from assigned to new

Reassigned back to Frank to regenerate the gdal_wrap.c file.

Changed 4 years ago by mloskot

  • version changed from 1.4.0 to svn-trunk

Changed 4 years ago by warmerdam

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

gdal_wrap.c regenerated with SWIG 1.1pl5. I also updated the GNUmakefile to use the command name swig11pl5 to emphasize the version required.

Note: See TracTickets for help on using tickets.