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) 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``.