Revert "🔒️ Use custom safe(r) pickler for webassets"

This reverts commit 0f41a4219b.
This commit is contained in:
Gina Häußge committed 2021-12-15 11:25:36 +01:00
1 parent e4f8ee9689
commit ff543a422e
2 files changed
+3 -58

No files matched your search

+3 -10
View File
@@ -175,12 +175,11 @@ def enable_additional_translations(default_locale="en", additional_folders=None)
def fix_webassets_cache():
from webassets import cache
import octoprint.util.safe_pickle
error_logger = logging.getLogger(__name__ + ".fix_webassets_cache")
def fixed_set(self, key, data):
import os
import pickle
import shutil
import tempfile
@@ -195,7 +194,7 @@ def fix_webassets_cache():
fd, temp_filename = tempfile.mkstemp(prefix="." + md5, dir=self.directory)
try:
with os.fdopen(fd, "wb") as f:
octoprint.util.safe_pickle.dump(data, f)
pickle.dump(data, f)
f.flush()
shutil.move(temp_filename, filename)
except Exception:
@@ -239,13 +238,7 @@ def fix_webassets_cache():
finally:
f.close()
try:
unpickled = octoprint.util.safe_pickle.safe_loads(result)
except Exception:
error_logger.exception(
"Got an exception while trying to load webasset file {}".format(filename)
)
return None
unpickled = webassets.cache.safe_unpickle(result)
if unpickled is None:
warnings.warn("Ignoring corrupted cache file %s" % filename)
return unpickled
-48
View File
@@ -1,48 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
__copyright__ = "Copyright (C) 2021 The OctoPrint Project - Released under terms of the AGPLv3 License"
import io
def _validate(module, name, allowed=None):
if allowed is None:
return None
return allowed.get((module, name), None)
try:
import cPickle as pickle # Python 2
def safe_load(f, allowed=None):
unpickler = pickle.Unpickler(f)
unpickler.find_global = lambda m, n: _validate(m, n, allowed=allowed)
return unpickler.load()
def safe_loads(s, allowed=None):
return safe_load(io.BytesIO(s), allowed=allowed)
except ImportError:
import pickle # Python 3
class RestrictedUnpickler(pickle.Unpickler):
def __init__(self, f, *args, **kwargs):
self.allowed = kwargs.get("allowed")
super(RestrictedUnpickler, self).__init__(f, *args, **kwargs)
def find_class(self, module, name):
return _validate(module, name, allowed=self.allowed)
def safe_load(f, allowed=None):
return RestrictedUnpickler(f, allowed=allowed).load()
def safe_loads(s, allowed=None):
return safe_load(io.BytesIO(s), allowed=allowed)
dump = pickle.dump
dumps = pickle.dumps