10000 gh-92930: _pickle.c: Acquire strong references before calling save() by sweeneyde · Pull Request #92931 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-92930: _pickle.c: Acquire strong references before calling save() #92931

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

Merged
merged 11 commits into from
Jun 11, 2022
Prev Previous commit
clean up test case, better name
  • Loading branch information
sweeneyde committed Jun 11, 2022
commit 370c44e650f01b2138e32590be7cbc271793b140
19 changes: 11 additions & 8 deletions Lib/test/pickletester.py
< 518D tr data-hunk="2921f0f72deb2f22388df2da811bd7785895b2bf9fe41da188f7720f93e8d85a" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,7 @@ def check_array(arr):
check_array(arr[::2])

def test_evil_class_mutating_dict(self):
# https://github.com/python/cpython/issues/92930
from random import getrandbits

global Bad
Expand Down Expand Up @@ -3064,25 +3065,27 @@ def __reduce__(self):
expected = "changed size during iteration"
self.assertIn(expected, str(e))

def test_evil_class_mutating_container(self):
def test_evil_pickler_mutating_collection(self):
# https://github.com/python/cpython/issues/92930
if not hasattr(self, "pickler"):
raise self.skipTest(f"{type(self)} has no associated pickler type")

global Clearer
class Clearer:
pass

def check(a):
class P(self.pickler):
def check(collection):
class EvilPickler(self.pickler):
def persistent_id(self, obj):
if isinstance(obj, Clearer):
a.clear()
collection.clear()
return None
pickler = EvilPickler(io.BytesIO(), proto)
try:
P(io.BytesIO(), proto).dump(a)
except RuntimeError:
# Don't care if this raises, just don't segfault.
pass
pickler.dump(collection)
except RuntimeError as e:
expected = "changed size during iteration"
self.assertIn(expected, str(e))

for proto in protocols:
check([Clearer()])
Expand Down
0