Commit cc261871 authored by tzickel's avatar tzickel

fixed negative length in pywsgi's Input read functions for non chunked body

parent 02eb41d9
......@@ -9,7 +9,7 @@
- Formatting run info no longer includes ``gevent.local.local``
objects that have no value in the greenlet. See :issue:`1275`.
- Fixed negative length in pywsgi's Input read functions for non chunked body.
1.3.6 (2018-08-17)
==================
......
......@@ -267,9 +267,6 @@ class Input(object):
if length == 0:
return b""
if length is not None and length < 0:
length = None
if use_readline:
reader = self.rfile.readline
else:
......@@ -312,11 +309,15 @@ class Input(object):
return b''.join(response)
def read(self, length=None):
if length is not None and length < 0:
length = None
if self.chunked_input:
return self._chunked_read(length)
return self._do_read(length)
def readline(self, size=None):
if size is not None and size < 0:
size = None
if self.chunked_input:
return self._chunked_read(size, True)
return self._do_read(size, use_readline=True)
......
......@@ -551,6 +551,58 @@ class TestBigChunks(TestChunkedApp):
chunks = [b'a' * 8192] * 3
class TestNegativeRead(TestCase):
@staticmethod
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
if env['PATH_INFO'] == '/read':
data = env['wsgi.input'].read(-1)
return [data]
def test_negative_chunked_read(self):
fd = self.makefile()
data = (b'POST /read HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
b'Transfer-Encoding: chunked\r\n\r\n'
b'2\r\noh\r\n4\r\n hai\r\n0\r\n\r\n')
fd.write(data)
read_http(fd, body='oh hai')
def test_negative_nonchunked_read(self):
fd = self.makefile()
data = (b'POST /read HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
b'Content-Length: 6\r\n\r\n'
b'oh hai')
fd.write(data)
read_http(fd, body='oh hai')
class TestNegativeReadline(TestCase):
validator = None
@staticmethod
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
if env['PATH_INFO'] == '/readline':
data = env['wsgi.input'].readline(-1)
return [data]
def test_negative_chunked_readline(self):
fd = self.makefile()
data = (b'POST /readline HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
b'Transfer-Encoding: chunked\r\n\r\n'
b'2\r\noh\r\n4\r\n hai\r\n0\r\n\r\n')
fd.write(data)
read_http(fd, body='oh hai')
def test_negative_nonchunked_readline(self):
fd = self.makefile()
data = (b'POST /readline HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n'
b'Content-Length: 6\r\n\r\n'
b'oh hai')
fd.write(data)
read_http(fd, body='oh hai')
class TestChunkedPost(TestCase):
@staticmethod
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment