From 03dd6a2cfca659186d6166c839474b57b8a3f637 Mon Sep 17 00:00:00 2001 From: Justin Applegate Date: Mon, 16 Jun 2025 11:56:46 -0400 Subject: [PATCH 1/2] Add a check for 0 items to `APPENDS` and `ADDITEMS` opcodes --- Lib/pickle.py | 4 ++++ Lib/test/pickletester.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Lib/pickle.py b/Lib/pickle.py index beaefae0479d3c..4639c4185f6786 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -1785,6 +1785,8 @@ def load_append(self): def load_appends(self): items = self.pop_mark() list_obj = self.stack[-1] + if len(items) == 0: # nothing to do + return try: extend = list_obj.extend except AttributeError: @@ -1818,6 +1820,8 @@ def load_setitems(self): def load_additems(self): items = self.pop_mark() set_obj = self.stack[-1] + if len(items) == 0: # nothing to do + return if isinstance(set_obj, set): set_obj.update(items) else: diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 9a3a26a8400844..49ad285da6f10b 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1105,6 +1105,10 @@ def test_large_binstring(self): with self.assertRaisesRegex(pickle.UnpicklingError, errmsg): self.loads(b'T\0\0\0\x80') + def test_appends_additems_no_items(self): + self.assertEqual(self.loads(b'K\x01(e.'), 1) + self.assertEqual(self.loads(b'K\x01(\x90.'), 1) + def test_get(self): pickled = b'((lp100000\ng100000\nt.' unpickled = self.loads(pickled) From 17717476662c866c79db48bad10a0ac07b926197 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 16 Jun 2025 16:02:08 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-06-16-16-02-05.gh-issue-135573.waQmoA.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-06-16-16-02-05.gh-issue-135573.waQmoA.rst diff --git a/Misc/NEWS.d/next/Library/2025-06-16-16-02-05.gh-issue-135573.waQmoA.rst b/Misc/NEWS.d/next/Library/2025-06-16-16-02-05.gh-issue-135573.waQmoA.rst new file mode 100644 index 00000000000000..425896da211658 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-06-16-16-02-05.gh-issue-135573.waQmoA.rst @@ -0,0 +1 @@ +Adds a check in the ``ADDITEMS`` and ``APPENDS`` opcodes of the Python implementation of :mod:`pickle` to return early if there's no items to add.