New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherrypy.wsgiserver.wsgiserver2.ChunkedRFile.__iter__ broken #1131

Closed
bb-migration opened this Issue Mar 9, 2012 · 3 comments

Comments

1 participant
@bb-migration

bb-migration commented Mar 9, 2012

Originally reported by: Anonymous


cherrypy.wsgiserver.wsgiserver2.ChunkedRFile.iter references sizehint, which is not defined:

My code:

#!python

def disable_prb():
    cherrypy.request.process_request_body = False
cherrypy.tools.disable_prb = cherrypy.Tool('before_request_body', disable_prb)

class Root(object):
    @cherrypy.expose
    @cherrypy.tools.disable_prb()
    def index(self):
        for line in cherrypy.request.rfile:
            print "got line: " + line

Error:

[09/Mar/2012:14:44:15] HTTP Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond
    response.body = self.handler()
  File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "server-put.py", line 19, in index
    for line in cherrypy.request.rfile:
  File "/usr/lib/python2.7/dist-packages/cherrypy/wsgiserver/wsgiserver2.py", line 513, in __iter__
    line = self.readline(sizehint)
NameError: global name 'sizehint' is not defined

wsgiserver2.py:

#!python

    def __iter__(self):
        # Shamelessly stolen from StringIO
        total = 0
        line = self.readline(sizehint)
        while line:
            yield line
            total += len(line)
            if 0 < sizehint <= total:
                break
            line = self.readline(sizehint)

@bb-migration

This comment has been minimized.

bb-migration commented Mar 9, 2012

Original comment by Jim Paris (Bitbucket: jimparis, GitHub: jimparis):


(I was the original reporter)

It's even worse. ChunkedRFile.read() and ChunkedRFile.readline() are both broken and get stuck in a loop if size = None.

I'll put together a testcase

@bb-migration

This comment has been minimized.

bb-migration commented Mar 9, 2012

Original comment by Jim Paris (Bitbucket: jimparis, GitHub: jimparis):


Attaching a patch to cherrypy/test/test_conn.py that should show the problems. Apply this and run

nosetests -s cherrypy.test.test_conn:ConnectionTests.test_Chunked_Encoding
@bb-migration

This comment has been minimized.

bb-migration commented Mar 9, 2012

Original comment by Jim Paris (Bitbucket: jimparis, GitHub: jimparis):


Two more patches.

The first one improves the test to include data that does not end in EOL, to trigger more bugs.

The second one fixes at least some of the bugs in ChunkedRFile so that these new test cases pass.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jul 19, 2017

wiz
Updated py-cheroot to 5.7.0.
v5.7.0
======

- CI improvements:
  * Don't run tests during deploy stage
  * Use VM based build job env only for pyenv envs
  * Opt-in for beta trusty image @ Travis CI
  * Be verbose when running tests (show test names)
  * Show xfail/skip details during test run

- #34: Fix ``_handle_no_ssl`` error handler calls

- #21: Fix ``test_conn`` tests:
  * Improve setup_server def in HTTP connection tests
  * Fix HTTP streaming tests
  * Fix HTTP/1.1 pipelining test under Python 3
  * Fix ``test_readall_or_close`` test
  * Fix ``test_No_Message_Body``
  * Clarify ``test_598`` fail reason

- #36: Add GitHub templates for PR, issue && contributing

- #27: Default HTTP Server header to Cheroot version str

- Cleanup _compat functions from server module

v5.6.0
======

- Fix all PEP 257 related errors in all non-test modules.

  ``cheroot/test/*`` folder is only one left allowed to fail with this linter.

- #30: Optimize chunked body reader loop by returning empty data is the size is 0.

  Ref: cherrypy/cherrypy#1602

- Reset buffer if the body size is unknown

  Ref: cherrypy/cherrypy#1486

- Add missing size hint to SizeCheckWrapper

  Ref: cherrypy/cherrypy#1131

v5.5.2
======

- #32: Ignore "unknown error" and "https proxy request" SSL errors.

  Ref: sabnzbd/sabnzbd#820

  Ref: sabnzbd/sabnzbd#860

v5.5.1
======

- Make Appveyor list separate tests in corresponding tab.

- #29: Configure Travis CI build stages.

  Prioritize tests by stages.

  Move deploy stage to be run very last after all other stages finish.

- #31: Ignore "Protocol wrong type for socket" (EPROTOTYPE) @ OSX for non-blocking sockets.

  This was originally fixed for regular sockets in cherrypy/cherrypy#1392.

  Ref: https://forums.sabnzbd.org/viewtopic.php?f=2&t=22728&p=112251

v5.5.0
======

- #17 via #25: Instead of a read_headers function, cheroot now
  supplies a HeaderReader class to perform the same function.

  Any HTTPRequest object may override the header_reader attribute
  to customize the handling of incoming headers.

  The server module also presents a provisional implementation of
  a DropUnderscoreHeaderReader that will exclude any headers
  containing an underscore. It remains an exercise for the
  implementer to demonstrate how this functionality might be
  employed in a server such as CherryPy.

- #26: Configured TravisCI to run tests under OS X.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment