[mod_python] SystemError: bad argument to internal function

Graham Dumpleton graham.dumpleton at gmail.com
Fri Jun 15 07:30:14 EDT 2007


I doubt it would be the image as one shouldn't be using
"application/x-www-form-urlencoded" for images. But then that may be
part of the problem as posting data with embedded nulls would probably
cause parse_qsl() to fail or at least give incorrect results because
it uses strlen() on data. Should really be using some form of
"multipart" content type for posts of binary data. For example
"multipart/mixed" perhaps.

If it isn't parse_qsl() the only other possibility is that req.read()
itself is broken in some subtle way and the problem is only triggered
when data is read off the wire in certain random block sizes. But why
this wouldn't be showing as a problem for lots of people I don't know.

FWIW, the actual problem is that _PyString_Resize() is being called
with what Python internally regards as an invalid value. Ie., fails
test:

        if (!PyString_Check(v) || v->ob_refcnt != 1 || newsize < 0 ||
            PyString_CHECK_INTERNED(v)) {
                *pv = 0;
                Py_DECREF(v);
                PyErr_BadInternalCall();
                return -1;
        }

Looking at parse_qsl() I can't see how it could get a wrong value.

One final question, is the incoming body of the request being
compressed in anyway when being sent by the browser as there are
issues in mod_python where an input filter is being applied to
incoming content and the content length of data is changed and ends up
different to the content length header. I only saw this as resulting
in truncated input, but maybe it causes other problems as well.

Graham

On 15/06/07, Clodoaldo <clodoaldo.pinto.neto at gmail.com> wrote:
> 2007/6/15, Graham Dumpleton <graham.dumpleton at gmail.com>:
> > Can you send the same POST content to a standard handler containing:
>
> The error was triggered by user input I and can't reproduce it. It
> happened only twice. To complicate it the same program meu_anuncio.py
> handles 2 forms and I don't know which one triggered the error. One of
> the forms uploads pictures. I have tested that program extensively and
> found no problems. Tried again now in the production machine and I
> can't trigger the error.
>
> In some hours I will post the content of a non error-triggering POST.
>
> Clodoaldo
>
> >
> >   def handler(req):
> >     req.content_type = 'text/plain'
> >     print >> req, req.headers_in["content-length"]
> >     print >> req, req.headers_in["content-type"]
> >     print >> req
> >     print >> req, req.read()
> >     return apache.OK
> >
> > Am expecting the content type to be
> > "application/x-www-form-urlencoded" which is triggering parse_qsl().
> > The intent of the above script is to capture the POST data so you can
> > post it and we can then use it as test data for calling parse_qsl()
> > direct.
> >
> > At this point figuring that parse_qsl() has bug.
> >
> > While you do that I'll look through parse_qsl() code and see if I can
> > see any problem.
> >
> > Graham
> >
> >
> >
> > On 15/06/07, Clodoaldo <clodoaldo.pinto.neto at gmail.com> wrote:
> > > 2007/6/14, Graham Dumpleton <graham.dumpleton at gmail.com>:
> > > > Did you ever sort this out?
> > >
> > > No
> > >
> > > > Which sub revision of Python 2.4 are you using? The source code line
> > > > numbers don't match up with anything meaningful in Python 2.4.3 source
> > > > code that I have on hand.
> > >
> > > Python 2.4.4 in Fedora Core 6, Apache 2.2.4, mod_python 3.3.1
> > >
> > > Clodoaldo
> > >
> > > > On 09/06/07, Clodoaldo <clodoaldo.pinto.neto at gmail.com> wrote:
> > > > > I have this in my error log and I don't know what it means or what to do:
> > > > >
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] mod_python
> > > > > (pid=15022, interpreter='carroarodo.com', phase='PythonHandler',
> > > > > handler='~/_publisher.py'): Application error, referer:
> > > > > http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] ServerName:
> > > > > 'carroarodo.com', referer: http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]
> > > > > DocumentRoot: '/var/www/html/carroarodo.com', referer:
> > > > > http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] URI:
> > > > > '/meu_anuncio', referer: http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] Location:
> > > > > None, referer: http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] Directory:
> > > > > '/var/www/html/carroarodo.com/', referer:
> > > > > http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] Filename:
> > > > > '/var/www/html/carroarodo.com/meu_anuncio.py', referer:
> > > > > http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] PathInfo:
> > > > > '', referer: http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225] Traceback
> > > > > (most recent call last):, referer: http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > "/usr/lib64/python2.4/site-packages/mod_python/importer.py", line
> > > > > 1537, in HandlerDispatch\n    default=default_handler, arg=req,
> > > > > silent=hlist.silent), referer: http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > "/usr/lib64/python2.4/site-packages/mod_python/importer.py", line
> > > > > 1229, in _process_target\n    result = _execute_target(config, req,
> > > > > object, arg), referer: http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > "/usr/lib64/python2.4/site-packages/mod_python/importer.py", line
> > > > > 1128, in _execute_target\n    result = object(arg), referer:
> > > > > http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > "/var/www/html/carroarodo.com/_publisher.py", line 5, in handler\n
> > > > > return publisher.handler(req), referer:
> > > > > http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > "/usr/lib64/python2.4/site-packages/mod_python/publisher.py", line
> > > > > 213, in handler\n    published = publish_object(req, object), referer:
> > > > > http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > "/usr/lib64/python2.4/site-packages/mod_python/publisher.py", line
> > > > > 424, in publish_object\n    req.form = util.FieldStorage(req,
> > > > > keep_blank_values=1), referer: http://carroarodo.com/meu_anuncio
> > > > > [Tue Jun 05 18:33:49 2007] [error] [client 200.155.85.225]   File
> > > > > "/usr/lib64/python2.4/site-packages/mod_python/util.py", line 225, in
> > > > > __init__\n    pairs = parse_qsl(req.read(clen), keep_blank_val[Tue Jun
> > > > > 05 18:33:49 2007] [error] [client 200.155.85.225] SystemError:
> > > > > Objects/stringobject.c:3515: bad argument to internal function,
> > > > > referer: http://carroarodo.com/meu_anuncio
> > > > >
> > > > > Any hints?
> > > > >
> > > > > Regards, Clodoaldo Pinto Neto
> > > >
> > >
> >
>


More information about the Mod_python mailing list