Skip to content

Commit 0d8f3b1

Browse files
committed
Fix on vulnerability report
#1695
1 parent 6e9e7ad commit 0d8f3b1

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ faceswap/
2626
.vscode/
2727
switch_states.json
2828
/models
29+
install.bat

modules/processors/frame/core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@
1717
'process_video'
1818
]
1919

20+
ALLOWED_PROCESSORS = {
21+
'face_swapper',
22+
'face_enhancer',
23+
'face_enhancer_gpen256',
24+
'face_enhancer_gpen512'
25+
}
2026

2127
def load_frame_processor_module(frame_processor: str) -> Any:
28+
if frame_processor not in ALLOWED_PROCESSORS:
29+
print(f"Frame processor {frame_processor} is not allowed")
30+
sys.exit()
2231
try:
2332
frame_processor_module = importlib.import_module(f'modules.processors.frame.{frame_processor}')
2433
for method_name in FRAME_PROCESSORS_INTERFACE:

modules/utilities.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
TEMP_FILE = "temp.mp4"
1616
TEMP_DIRECTORY = "temp"
1717

18-
# monkey patch ssl for mac
19-
if platform.system().lower() == "darwin":
20-
ssl._create_default_https_context = ssl._create_unverified_context
21-
2218

2319
def run_ffmpeg(args: List[str]) -> bool:
2420
"""Run ffmpeg with hardware acceleration and optimized settings."""
@@ -286,16 +282,29 @@ def conditional_download(download_directory_path: str, urls: List[str]) -> None:
286282
download_directory_path, os.path.basename(url)
287283
)
288284
if not os.path.exists(download_file_path):
289-
request = urllib.request.urlopen(url) # type: ignore[attr-defined]
290-
total = int(request.headers.get("Content-Length", 0))
285+
request = urllib.request.Request(url)
286+
287+
# Create a specific SSL context for macOS to avoid globally disabling verification
288+
ctx = None
289+
if platform.system().lower() == "darwin":
290+
ctx = ssl._create_unverified_context()
291+
292+
response = urllib.request.urlopen(request, context=ctx)
293+
total = int(response.headers.get("Content-Length", 0))
291294
with tqdm(
292295
total=total,
293296
desc="Downloading",
294297
unit="B",
295298
unit_scale=True,
296299
unit_divisor=1024,
297300
) as progress:
298-
urllib.request.urlretrieve(url, download_file_path, reporthook=lambda count, block_size, total_size: progress.update(block_size)) # type: ignore[attr-defined]
301+
with open(download_file_path, "wb") as f:
302+
while True:
303+
buffer = response.read(8192)
304+
if not buffer:
305+
break
306+
f.write(buffer)
307+
progress.update(len(buffer))
299308

300309

301310
def resolve_relative_path(path: str) -> str:

0 commit comments

Comments
 (0)