8000 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
Next Next commit
simplify test
  • Loading branch information
sweeneyde committed May 18, 2022
commit 7af44c4fac14d6d7ed487b21d856ddafb66acbb9
26 changes: 8 additions & 18 deletions Lib/test/pickletester.py
Original file line number Diff line number Diff line change
Expand Up @@ -3041,35 +3041,25 @@ def test_evil_class_mutating_dict(self):
global Bad
class Bad:
def __eq__(self, other):
if not ENABLED:
return False
return getrandbits(4) == 0
return ENABLED
def __hash__(self):
return getrandbits(1)
return 42
def __reduce__(self):
break_things()
return (Bad, (), ())
def __setstate__(self, *args):
break_things()
def __del__(self):
break_things()
def __getattr__(self):
break_things()

def break_things():
if ENABLED and getrandbits(6) == 0:
collection.clear()
if getrandbits(6) == 0:
collection.clear()
return (Bad, ())

for proto in protocols:
for _ in range(20):
ENABLED = False
collection = {Bad(): Bad() for _ in range(50)}
collection = {Bad(): Bad() for _ in range(20)}
for bad in collection:
bad.bad = bad
bad.collection = collection
ENABLED = True
try:
self.loads(self.dumps(collection, proto))
data = self.dumps(collection, proto)
self.loads(data)
except RuntimeError as e:
expected = "changed size during iteration"
self.assertIn(expected, str(e))
Expand Down
0