From d7bb2fb42e02bc8cd7c47ade1cdd416f7d77ea1e Mon Sep 17 00:00:00 2001 From: tonghuaroot Date: Thu, 16 Jul 2026 17:29:50 +0800 Subject: [PATCH 1/2] gh-153803: Raise ResponseError for a malformed struct in xmlrpc.client --- Lib/test/test_xmlrpc.py | 7 +++++++ Lib/xmlrpc/client.py | 2 ++ .../Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst | 3 +++ 3 files changed, 12 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index ee0e24f6e86ae33..834e772713e98f2 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -252,6 +252,13 @@ def test_loads_unsupported(self): '') self.assertRaises(ResponseError, xmlrpclib.loads, data) + def test_loads_malformed_struct(self): + ResponseError = xmlrpclib.ResponseError + data = ('' + 'k' + '') + self.assertRaises(ResponseError, xmlrpclib.loads, data) + 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 84e4e4d11a7319e..b4065b3d7f3f280 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -756,6 +756,8 @@ def end_struct(self, data): # map structs to Python dictionaries dict = {} items = self._stack[mark:] + if len(items) % 2: + raise ResponseError() for i in range(0, len(items), 2): dict[items[i]] = items[i+1] self._stack[mark:] = [dict] diff --git a/Misc/NEWS.d/next/Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst b/Misc/NEWS.d/next/Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst new file mode 100644 index 000000000000000..0ec678db63feb18 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst @@ -0,0 +1,3 @@ +Fix :func:`xmlrpc.client.loads` raising :exc:`IndexError` instead of +:exc:`~xmlrpc.client.ResponseError` for a malformed ````. Patch by +tonghuaroot. From 9694cbdd6eedb3ad2a6e33c644f99dae26adbf2c Mon Sep 17 00:00:00 2001 From: tonghuaroot Date: Thu, 16 Jul 2026 23:11:37 +0800 Subject: [PATCH 2/2] Fix NEWS cross-reference for ResponseError --- .../Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst b/Misc/NEWS.d/next/Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst index 0ec678db63feb18..08f54899cd1df2d 100644 --- a/Misc/NEWS.d/next/Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst +++ b/Misc/NEWS.d/next/Library/2026-07-16-12-00-00.gh-issue-153803.YbLNRy.rst @@ -1,3 +1,2 @@ Fix :func:`xmlrpc.client.loads` raising :exc:`IndexError` instead of -:exc:`~xmlrpc.client.ResponseError` for a malformed ````. Patch by -tonghuaroot. +``ResponseError`` for a malformed ````. Patch by tonghuaroot.