Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
66b7d758
Commit
66b7d758
authored
Oct 11, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
become even stricter with pickles
no pickle shall pass thank you again, RyotaK
parent
a05c8243
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
modules/safe.py
modules/safe.py
+17
-0
No files found.
modules/safe.py
View file @
66b7d758
...
...
@@ -10,6 +10,7 @@ import torch
import
numpy
import
_codecs
import
zipfile
import
re
# PyTorch 1.13 and later have _TypedStorage renamed to TypedStorage
...
...
@@ -54,11 +55,27 @@ class RestrictedUnpickler(pickle.Unpickler):
raise
pickle
.
UnpicklingError
(
f
"global '{module}/{name}' is forbidden"
)
allowed_zip_names
=
[
"archive/data.pkl"
,
"archive/version"
]
allowed_zip_names_re
=
re
.
compile
(
r"^archive/data/\d+$"
)
def
check_zip_filenames
(
filename
,
names
):
for
name
in
names
:
if
name
in
allowed_zip_names
:
continue
if
allowed_zip_names_re
.
match
(
name
):
continue
raise
Exception
(
f
"bad file inside {filename}: {name}"
)
def
check_pt
(
filename
):
try
:
# new pytorch format is a zip file
with
zipfile
.
ZipFile
(
filename
)
as
z
:
check_zip_filenames
(
filename
,
z
.
namelist
())
with
z
.
open
(
'archive/data.pkl'
)
as
file
:
unpickler
=
RestrictedUnpickler
(
file
)
unpickler
.
load
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment