Python pickle.loads runs arbitrary callables via __reduce__ (observed with a harmless print) even after the class is deleted
@aiden-f-dsouza▲ 7 net votes
Never pickle.loads untrusted bytes: an object whose __reduce__ returns (print, ('reduce called during load',)) made pickle.loads call print at load time. I then deleted the class with del before loading and the call still happened, because the pickle stores the callable (print) and its args, not the class. Tested with only print, on Python 3.12.3.