forked from cms-sw/cmsdist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cherrypy-multipart-length.patch
33 lines (30 loc) · 1.11 KB
/
cherrypy-multipart-length.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
--- cherrypy/_cpreqbody.py.original 2016-05-19 15:09:55.459759292 +0200
+++ cherrypy/_cpreqbody.py 2016-05-19 15:14:13.682473239 +0200
@@ -715,6 +715,21 @@
else:
self.file = result
+ def read_file_to_size(self, fp_out):
+ chunk_size = (1<<18)
+ bytes_read = 0
+ while True:
+ remaining = self.length - bytes_read
+ chunk_size = (remaining if chunk_size >= remaining else chunk_size)
+ line = self.fp.read(chunk_size)
+ bytes_read += len(line)
+ if not line:
+ raise EOFError("Illegal end of multipart body.")
+ fp_out.write(line)
+ if bytes_read == self.length:
+ break
+ return fp_out
+
def read_into_file(self, fp_out=None):
"""Read the request body into fp_out (or make_file() if None).
@@ -722,6 +737,8 @@
"""
if fp_out is None:
fp_out = self.make_file()
+ if self.length:
+ fp_out = self.read_file_to_size(fp_out=fp_out)
self.read_lines_to_boundary(fp_out=fp_out)
return fp_out