Skip to content

gh-135573: Add a check for 0 items to APPENDS and ADDITEMS opcodes #135574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add a check for 0 items to APPENDS and ADDITEMS opcodes
  • Loading branch information
Legoclones committed Jun 16, 2025
commit 03dd6a2cfca659186d6166c839474b57b8a3f637
4 changes: 4 additions & 0 deletions Lib/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/pickletester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading