Skip to content

Security Fix for Arbitrary Code Execution - huntr.dev #1163

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tflearn/datasets/cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,32 @@

import numpy as np
import pickle
import io
import builtins

safe_builtins = {
'range',
'complex',
'set',
'frozenset',
'slice',
}

from ..data_utils import to_categorical

class RestrictedUnpickler(pickle.Unpickler):

def find_class(self, module, name):
"""Only allow safe classes from builtins"""
if module == "builtins" and name in safe_builtins:
return getattr(builtins, name)
"""Forbid everything else"""
raise pickle.UnpicklingError("global '%s.%s' is forbidden" %
(module, name))

def restricted_loads(s):
"""Helper function analogous to pickle.loads()"""
return RestrictedUnpickler(io.BytesIO(s)).load()

def load_data(dirname="cifar-10-batches-py", one_hot=False):
tarpath = maybe_download("cifar-10-python.tar.gz",
Expand Down Expand Up @@ -56,9 +79,11 @@ def load_batch(fpath):
with open(fpath, 'rb') as f:
if sys.version_info > (3, 0):
# Python3
restricted_loads(f.read())
d = pickle.load(f, encoding='latin1')
else:
# Python2
restricted_loads(f.read())
d = pickle.load(f)
data = d["data"]
labels = d["labels"]
Expand Down