diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index ee0e24f6e86ae3..e8ef537b84e2cb 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -252,6 +252,16 @@ def test_loads_unsupported(self): '') self.assertRaises(ResponseError, xmlrpclib.loads, data) + def test_loads_nested_scalars(self): + template = '%s' + data = template % 'a' + values, _ = xmlrpclib.loads(data) + self.assertEqual(values, ('ab', '')) + + data = template % '12' + values, _ = xmlrpclib.loads(data) + self.assertEqual(values, (1, 2)) + def check_loads(self, s, value, **kwargs): dump = '%s' % s result, m = xmlrpclib.loads(dump, **kwargs) diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 84e4e4d11a7319..0d26ad03c51e73 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -677,7 +677,9 @@ def end(self, tag): f = self.dispatch[tag.split(':')[-1]] except KeyError: return # unknown tag ? - return f(self, "".join(self._data)) + data = "".join(self._data) + self._data.clear() + return f(self, data) # # accelerator support diff --git a/Misc/NEWS.d/next/Library/2026-11-19-19-44-33.gh-issue-162285.wnH4aQ.rst b/Misc/NEWS.d/next/Library/2026-11-19-19-44-33.gh-issue-162285.wnH4aQ.rst new file mode 100644 index 00000000000000..f839943746e10d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-11-19-19-44-33.gh-issue-162285.wnH4aQ.rst @@ -0,0 +1,2 @@ +Fix quadratic memory use in :mod:`xmlrpc.client` when decoding malformed +XML-RPC packets containing nested string elements.