From ae872919f2833567d5f14f10f9729989ae2f39b8 Mon Sep 17 00:00:00 2001 From: Saba Siddique Date: Tue, 3 Feb 2026 16:02:37 +0500 Subject: [PATCH 1/4] gh-144412: require tuple args in pickle REDUCE --- Lib/pickle.py | 2 ++ Lib/test/pickletester.py | 1 + 2 files changed, 3 insertions(+) diff --git a/Lib/pickle.py b/Lib/pickle.py index 71c12c50f7f035..af2803c15be199 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -1724,6 +1724,8 @@ def load_reduce(self): stack = self.stack args = stack.pop() func = stack[-1] + if not isinstance(args, tuple): + raise TypeError("argument list must be a tuple") stack[-1] = func(*args) dispatch[REDUCE[0]] = load_reduce diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index d2b8d036bfd9e7..2126e30cc6cbf3 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1435,6 +1435,7 @@ def test_bad_reduce(self): self.assertEqual(self.loads(b'cbuiltins\nint\n)R.'), 0) self.check_unpickling_error(TypeError, b'N)R.') self.check_unpickling_error(TypeError, b'cbuiltins\nint\nNR.') + self.check_unpickling_error(TypeError, b'cbuiltins\nint\nNR.') def test_bad_newobj(self): error = (pickle.UnpicklingError, TypeError) From e6dfc103efd9b762316ce120e02ca718e7fbcd8c Mon Sep 17 00:00:00 2001 From: Saba Siddique Date: Tue, 3 Feb 2026 16:06:39 +0500 Subject: [PATCH 2/4] gh-144412: add NEWS entry for pickle REDUCE fix --- .../next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst diff --git a/Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst b/Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst new file mode 100644 index 00000000000000..8b4c77eb3829df --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst @@ -0,0 +1,2 @@ +``pickle.load_reduce()`` now requires a tuple for ``REDUCE`` arguments to +match ``_pickle``; non-tuple argument lists now raise ``TypeError``. From bcfd96f6702518177208a2337a044bf01d549177 Mon Sep 17 00:00:00 2001 From: Saba Siddique Date: Tue, 3 Feb 2026 16:20:53 +0500 Subject: [PATCH 3/4] gh-144412: rename NEWS entry file --- .../next/Library/2026-02-03-12-00-00.gh-issue-144412.q7KpXg.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-02-03-12-00-00.gh-issue-144412.q7KpXg.rst diff --git a/Misc/NEWS.d/next/Library/2026-02-03-12-00-00.gh-issue-144412.q7KpXg.rst b/Misc/NEWS.d/next/Library/2026-02-03-12-00-00.gh-issue-144412.q7KpXg.rst new file mode 100644 index 00000000000000..8b4c77eb3829df --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-02-03-12-00-00.gh-issue-144412.q7KpXg.rst @@ -0,0 +1,2 @@ +``pickle.load_reduce()`` now requires a tuple for ``REDUCE`` arguments to +match ``_pickle``; non-tuple argument lists now raise ``TypeError``. From c94ad8b2c790a3f43f90ab1140e049cdf67cfc21 Mon Sep 17 00:00:00 2001 From: Sabaa Siddique <103187876+sabasiddique1@users.noreply.github.com> Date: Tue, 3 Feb 2026 16:23:20 +0500 Subject: [PATCH 4/4] Delete Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst --- .../next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst diff --git a/Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst b/Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst deleted file mode 100644 index 8b4c77eb3829df..00000000000000 --- a/Misc/NEWS.d/next/Library/2026-01-31-12-40-00.gh-issue-000000.vXyZ0a.rst +++ /dev/null @@ -1,2 +0,0 @@ -``pickle.load_reduce()`` now requires a tuple for ``REDUCE`` arguments to -match ``_pickle``; non-tuple argument lists now raise ``TypeError``.