Skip to content

Commit

Permalink
resolve pickle security issue
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-husky committed Nov 4, 2024
1 parent 4f0851f commit 91f5e6b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crazy_functions/latex_fns/latex_pickle_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ class SafeUnpickler(pickle.Unpickler):
def get_safe_classes(self):
from crazy_functions.latex_fns.latex_actions import LatexPaperFileGroup, LatexPaperSplit
from crazy_functions.latex_fns.latex_toolbox import LinkedListNode
from numpy.core.multiarray import scalar
from numpy import dtype
# 定义允许的安全类
safe_classes = {
# 在这里添加其他安全的类
'LatexPaperFileGroup': LatexPaperFileGroup,
'LatexPaperSplit': LatexPaperSplit,
'LinkedListNode': LinkedListNode,
'scalar': scalar,
'dtype': dtype,
}
return safe_classes

Expand All @@ -22,8 +26,6 @@ def find_class(self, module, name):
for class_name in self.safe_classes.keys():
if (class_name in f'{module}.{name}'):
match_class_name = class_name
if module == 'numpy' or module.startswith('numpy.'):
return super().find_class(module, name)
if match_class_name is not None:
return self.safe_classes[match_class_name]
# 如果尝试加载未授权的类,则抛出异常
Expand Down

0 comments on commit 91f5e6b

Please sign in to comment.