I did encounter same problem recently. I have inspected how it works, and
eventually understand why it goes wrong. It's not a bug of webob, it's a bug
of uWSGI. I did write a simple wsgi app to reproduce the issue,

def application(environ, start_response):
    input = environ['wsgi.input']
    while True:
        line = input.readline()
        if not line:
            break
        print repr(line)

run it with uwsgi and submit a multipart/form-data from. Following lines are
the output

'-----------------------------256672629917035\r'
'Content-Disposition: form-data; name="title"\r\n'
'\r\n'

As you can see, the '\n' of first line is not there in the result of the
first line, that's why webob thinks there are no more data to read. I have
read source code of uwsgi_Input_getline in plugins/python/wsgi_handlers.c,
but still, I can't tell why the tail '\n' of first line disappears. However,
obviously, it's a bug of uWSGI.

To workaround this bug, you can access request.body before accessing the
form fields, it forces webob to copy the whole body, and then the params,
str_POST can be read correctly..

Hope this would be helpful.
Victor Lin.


>>**>>* On 09/02/2011 02:05 PM, Roberto De Ioris wrote:*>>>>* Seems setting 
>>post-buffering was the trick.*>>>>**>>>>* 
>><post-buffering>8192</post-buffering>*>>>**>>>* Should not be needed in 
>>latest release, i will investigate on this*>>>**>>>* Is this a custom 
>>webob-based app or a pylons one ?*>>>**>>>**>>* Pyramid 1.1*>>* 
>>_______________________________________________*>>**>
> The situation is a bit messy, first of all the new webob feature
> (check_disconnection) will require our readline() implementation to read
> the full body if it does not contain a good amount of '\n'.
>
> Even if it is perfectly legal (this is how python readline() works) this
> will be a security flaw for uWSGI as a malicious upload could allocate a
> big amount of memory (this could happen even for read() but
> users/developers have become more smart with this). Enabling
> --post-buffering will map the request body to a file, using the native
> python readline(), making webob happy.
>
> Another strange thing is that even if i enable --post-buffering during an
> upload and i do not call req.body but only req.POST i receive the same
> error generated by check_disconnection.
>
> I think it is better for me to talk about it with Ian Bicking, he could
> point me to some better solution/explanation.
>
> --
> Roberto De Ioris
> http://unbit.it
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to