summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpc
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-12-06 01:34:56 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-12-06 01:34:56 (GMT)
commiteca72d47f5a639a0ac66a98a2d63b30df2ce310f (patch)
tree5c67eee0bab41a933c82c1d0d2540e4215cad215 /Lib/xmlrpc
parentf990e7f1f0de45a07bab0e520d01f706b6f46569 (diff)
parent81b7374fbe5f77567642d5aa42d4c1e6eee610b2 (diff)
downloadcpython-eca72d47f5a639a0ac66a98a2d63b30df2ce310f.zip
cpython-eca72d47f5a639a0ac66a98a2d63b30df2ce310f.tar.gz
cpython-eca72d47f5a639a0ac66a98a2d63b30df2ce310f.tar.bz2
merge 3.3 (#16043)
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r--Lib/xmlrpc/client.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py
index 50cedfc..e8c1944 100644
--- a/Lib/xmlrpc/client.py
+++ b/Lib/xmlrpc/client.py
@@ -49,6 +49,7 @@
# 2003-07-12 gp Correct marshalling of Faults
# 2003-10-31 mvl Add multicall support
# 2004-08-20 mvl Bump minimum supported Python version to 2.1
+# 2014-12-02 ch/doko Add workaround for gzip bomb vulnerability
#
# Copyright (c) 1999-2002 by Secret Labs AB.
# Copyright (c) 1999-2002 by Fredrik Lundh.
@@ -1030,10 +1031,13 @@ def gzip_encode(data):
# in the HTTP header, as described in RFC 1952
#
# @param data The encoded data
+# @keyparam max_decode Maximum bytes to decode (20MB default), use negative
+# values for unlimited decoding
# @return the unencoded data
# @raises ValueError if data is not correctly coded.
+# @raises ValueError if max gzipped payload length exceeded
-def gzip_decode(data):
+def gzip_decode(data, max_decode=20971520):
"""gzip encoded data -> unencoded data
Decode data using the gzip content encoding as described in RFC 1952
@@ -1043,11 +1047,16 @@ def gzip_decode(data):
f = BytesIO(data)
gzf = gzip.GzipFile(mode="rb", fileobj=f)
try:
- decoded = gzf.read()
+ if max_decode < 0: # no limit
+ decoded = gzf.read()
+ else:
+ decoded = gzf.read(max_decode + 1)
except OSError:
raise ValueError("invalid data")
f.close()
gzf.close()
+ if max_decode >= 0 and len(decoded) > max_decode:
+ raise ValueError("max gzipped payload length exceeded")
return decoded
##