Skip to content

Commit 8096488

Browse files
committed
gh-162285: Consume XML-RPC character data once per element
For nested <string> elements, each closing tag joined the same text fragments and retained another copy on the value stack. Clear the fragments after joining them to avoid quadratic memory use.
1 parent 562f08d commit 8096488

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎Lib/test/test_xmlrpc.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,16 @@ def test_loads_unsupported(self):
252252
'</struct></value></param></params>')
253253
self.assertRaises(ResponseError, xmlrpclib.loads, data)
254254

255+
def test_loads_nested_scalars(self):
256+
template = '<params><param><value>%s</value></param></params>'
257+
data = template % '<string><string>a<![CDATA[b]]></string></string>'
258+
values, _ = xmlrpclib.loads(data)
259+
self.assertEqual(values, ('ab', ''))
260+
261+
data = template % '<int><int>1</int>2</int>'
262+
values, _ = xmlrpclib.loads(data)
263+
self.assertEqual(values, (1, 2))
264+
255265
def check_loads(self, s, value, **kwargs):
256266
dump = '<params><param><value>%s</value></param></params>' % s
257267
result, m = xmlrpclib.loads(dump, **kwargs)

‎Lib/xmlrpc/client.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ def end(self, tag):
677677
f = self.dispatch[tag.split(':')[-1]]
678678
except KeyError:
679679
return # unknown tag ?
680-
return f(self, "".join(self._data))
680+
data = "".join(self._data)
681+
self._data.clear()
682+
return f(self, data)
681683

682684
#
683685
# accelerator support
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix quadratic memory use in :mod:`xmlrpc.client` when decoding malformed
2+
XML-RPC packets containing nested string elements.

0 commit comments

Comments
 (0)