Opened 17 years ago

Last modified 16 years ago

#2299 reopened defect

Python Mapscript bindings segfault

Reported by: crschmidt Owned by: hobu
Priority: high Milestone: FUTURE
Component: MapScript-Python Version: 5.0
Severity: critical Keywords:
Cc: tomkralidis

Description

        wms = mapscript.mapObj(self.mapfile)
        req = mapscript.OWSRequest()
        req.setParameter("bbox", tile.bbox())
        req.setParameter("width", str(tile.size()[0]))
        req.setParameter("height", str(tile.size()[1]))
        req.setParameter("srs", self.srs)
        req.setParameter("format", self.format())
        req.setParameter("layers", self.layers)
        wms.loadOWSParameters(req)

This usage is still causing segfaults in 5.0.0-Beta5. It's possible a later build fixes this: I couldn't find an open bug. I'll upload a test case in a moment.

Change History (11)

comment:1 by hobu, 17 years ago

#0  0x90026782 in strcasecmp ()
#1  0x01117434 in msWMSLoadGetMapParams (map=0x1842400, nVersion=65793, names=0x31f860, values=0x31f9f0, numentries=2) at mapwms.c:855
#2  0x0109eff5 in msMapLoadOWSParameters (map=0x1842400, request=0x31c750, wmtver=0x11493c4 "1.1.1") at mapobject.c:682
#3  0x0101e659 in _wrap_mapObj_loadOWSParameters (self=0x0, args=0x7adf0) at mapscript_wrap.c:4049
#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 ()

comment:2 by hobu, 17 years ago

using test.map in ./tests

import mapscript
m = mapscript.mapObj('test.map')
req = mapscript.OWSRequest()

req.setParameter("bbox", '-93,42,-92,43')
req.setParameter("layers", 'RASTER')
m.loadOWSParameters(req)

comment:3 by crschmidt, 17 years ago

Cc: tomkralidis added

This is the result of #1088.

Adding:

req.setParameter("styles", "") req.setParameter("request", "GetMap")

Fixes the problem.

I'm personally of the opinion that these should just be defaults, But if they're not going to be, this still needs to throw an exception.

comment:4 by tomkralidis, 17 years ago

FYI #1088 never touched the request parameter. If the example above is in a WMS client sense, then yes, an exception should be returned by any given WMS server if the request parameter is not present.

Not sure why the segfault is happenning though. When I run the code in comment:2, my httpd logs never show a connection to the WMS server I'm invoking a request against. This tells me that the segfault happens before the request is sent.

comment:5 by dmorissette, 17 years ago

Resolution: fixed
Status: newclosed

Thanks for the GDB backtrace hobu. The segfault happened because of a test on request (looking for DescribeLayer) added in r6551, possibly to fix a side-effect of #1088 but we'll never know since there is no associated ticket.

I've added a check in r6873 to test for request being NULL before attempting a strcmp(). I'm not setup to test with Python MapScript so please reopen if the fix doesn't solve your issue.

comment:6 by tomkralidis, 17 years ago

When I try this now:

import mapscript

req = mapscript.OWSRequest()

map = mapscript.mapObj('./somemap.map')

mapscript.msIO_installStdoutToBuffer()
req.setParameter('SERVICE','WMS')
req.setParameter('VERSION','1.1.1')
req.setParameter('LAYERS','obs')
#req.setParameter('REQUEST','DescribeLayer')
map.OWSDispatch( req )

content_type = mapscript.msIO_stripStdoutBufferContentType()
content = mapscript.msIO_getStdoutBufferBytes()

if content_type == 'vnd.ogc.se_xml':
  content_type = 'text/xml'

print 'Content-type: ' + content_type
print
print content

Uncommenting req.setParameter returns a non exception response. As is it returns an exception, as expected.

comment:7 by brentp, 16 years ago

Milestone: 5.0 releaseFUTURE
Resolution: fixed
Status: closedreopened
Summary: Python Mapscript bindings segfault TileCachePython Mapscript bindings segfault

with SVN trunk, and using the tests/test.map, you get a segfault when setting styles to None. that can happen if you use cgi.parse_qsl(environQUERY_STRING)

import mapscript
req = mapscript.OWSRequest()
map = mapscript.mapObj('test.map')

mapscript.msIO_installStdoutToBuffer()
req.setParameter('SERVICE','WMS')
req.setParameter('VERSION','1.1.1')
req.setParameter('LAYERS','obs')
req.setParameter('STYLE', None)
map.OWSDispatch( req )
  

in reply to:  7 comment:8 by brentp, 16 years ago

s/STYLE/STYLES/

Replying to brentp:

with SVN trunk, and using the tests/test.map, you get a segfault when setting styles to None. that can happen if you use cgi.parse_qsl(environQUERY_STRING)

import mapscript
req = mapscript.OWSRequest()
map = mapscript.mapObj('test.map')

mapscript.msIO_installStdoutToBuffer()
req.setParameter('SERVICE','WMS')
req.setParameter('VERSION','1.1.1')
req.setParameter('LAYERS','obs')
req.setParameter('STYLE', None)
map.OWSDispatch( req )
  

comment:9 by tomkralidis, 16 years ago

FYI, using the test snippet in comment:7, if I set any of the parameters to None, I get a segfault

comment:10 by brentp, 16 years ago

i dont know if this helps diagnose, but it's possible to recreate a segfault with no None's -- running this on tests/test.map

import mapscript

map = mapscript.mapObj('test.map')
req = mapscript.OWSRequest()

req.setParameter('SERVICE','WMS')
req.setParameter('STYLES', ',')
req.setParameter('VERSION','1.1.1')
req.setParameter('LAYERS','RASTER')
req.setParameter('REQUEST','GetMap')
req.setParameter('WIDTH', '500')
req.setParameter('HEIGHT', '500')
req.setParameter('SRS', 'EPSG:4326')
req.setParameter('FORMAT', 'image/png')
req.setParameter('BBOX', '-8,51,-2,59')
map.OWSDispatch( req )

comment:11 by tomkralidis, 16 years ago

Same segfault happens when tested similarly in Perl, for example:

$req->setParameter("STYLES", undef);

Note: See TracTickets for help on using tickets.