MCPcopy Index your code
hub / github.com/python/cpython / test_pickle

Function test_pickle

Lib/test/audit-tests.py:138–156  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

136
137
138def test_pickle():
139 import pickle
140
141 class PicklePrint:
142 def __reduce_ex__(self, p):
143 return str, ("Pwned!",)
144
145 payload_1 = pickle.dumps(PicklePrint())
146 payload_2 = pickle.dumps(("a", "b", "c", 1, 2, 3))
147
148 # Before we add the hook, ensure our malicious pickle loads
149 assertEqual("Pwned!", pickle.loads(payload_1))
150
151 with TestHook(raise_on_events="pickle.find_class") as hook:
152 with assertRaises(RuntimeError):
153 # With the hook enabled, loading globals is not allowed
154 pickle.loads(payload_1)
155 # pickles with no globals are okay
156 pickle.loads(payload_2)
157
158
159def test_monkeypatch():

Callers

nothing calls this directly

Calls 6

PicklePrintClass · 0.85
assertEqualFunction · 0.85
assertRaisesFunction · 0.85
TestHookClass · 0.70
dumpsMethod · 0.45
loadsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…