summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpclib.py
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2001-10-17 22:53:33 (GMT)
committerSkip Montanaro <skip@pobox.com>2001-10-17 22:53:33 (GMT)
commit5449e08412a5abd83c21d59764ef6240c58872b0 (patch)
tree0843a001023026c3fbcb59bd42a87f6f9af4d3e0 /Lib/xmlrpclib.py
parent07227d1ec027b8a6b189fecf4ac9eb555e2b0ec7 (diff)
downloadcpython-5449e08412a5abd83c21d59764ef6240c58872b0.zip
cpython-5449e08412a5abd83c21d59764ef6240c58872b0.tar.gz
cpython-5449e08412a5abd83c21d59764ef6240c58872b0.tar.bz2
test for int and long int overflow (allows operation on 64-bit platforms)
closes patch 470254
Diffstat (limited to 'Lib/xmlrpclib.py')
-rw-r--r--Lib/xmlrpclib.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index fda68e7..f5955cf 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -34,6 +34,7 @@
# 2001-10-01 fl Remove containers from memo cache when done with them
# 2001-10-01 fl Use faster escape method (80% dumps speedup)
# 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow
+# 2001-10-17 sm test for int and long overflow (allows use on 64-bit systems)
#
# Copyright (c) 1999-2001 by Secret Labs AB.
# Copyright (c) 1999-2001 by Fredrik Lundh.
@@ -144,6 +145,9 @@ def escape(s, replace=string.replace):
s = replace(s, "<", "&lt;")
return replace(s, ">", "&gt;",)
+MAXINT = 2L**31-1
+MININT = -2L**31
+
if unicode:
def _stringify(string):
# convert to 7-bit ascii if possible
@@ -462,12 +466,17 @@ class Marshaller:
f(self, value)
def dump_int(self, value):
+ # in case ints are > 32 bits
+ if value > MAXINT or value < MININT:
+ raise OverflowError, "int exceeds XML-RPC limits"
self.write("<value><int>%s</int></value>\n" % value)
dispatch[IntType] = dump_int
def dump_long(self, value):
- val = int(value)
- self.write("<value><int>%s</int></value>\n" % val)
+ # in case ints are > 32 bits
+ if value > MAXINT or value < MININT:
+ raise OverflowError, "long int exceeds XML-RPC limits"
+ self.write("<value><int>%s</int></value>\n" % int(value))
dispatch[LongType] = dump_long
def dump_double(self, value):