Opened 17 years ago

Closed 17 years ago

#1718 closed defect (fixed)

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: Mateusz Łoskot

Description (last modified by hobu)

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 (10)

comment:1 by hobu, 17 years ago

Description: modified (diff)

comment:2 by warmerdam, 17 years ago

Component: defaultOGR_SRS
Keywords: proj4 added
Milestone: 1.5.01.4.3
Resolution: fixed
Status: newclosed
Version: unspecified1.4.0

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.

comment:3 by Mateusz Łoskot, 17 years ago

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", "" );

} }}}

comment:4 by Mateusz Łoskot, 17 years ago

Cc: Mateusz Łoskot added

comment:5 by Mateusz Łoskot, 17 years ago

Resolution: fixed
Status: closedreopened

comment:6 by Mateusz Łoskot, 17 years ago

Owner: changed from warmerdam to Mateusz Łoskot
Status: reopenednew

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

comment:7 by Mateusz Łoskot, 17 years ago

Status: newassigned

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.

comment:8 by Mateusz Łoskot, 17 years ago

Owner: changed from Mateusz Łoskot to warmerdam
Status: assignednew

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

comment:9 by Mateusz Łoskot, 17 years ago

Version: 1.4.0svn-trunk

comment:10 by warmerdam, 17 years ago

Resolution: fixed
Status: newclosed

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.