Fix incomplete URL substring sanitation (#7056)

Resolves code scanning alert in https://github.com/ultralytics/yolov5/issues/7055
This commit is contained in:
Glenn Jocher 2022-03-20 14:18:05 +01:00 committed by GitHub
parent 6843ea5d7f
commit 9f4d11379b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -15,6 +15,7 @@ from itertools import repeat
from multiprocessing.pool import Pool, ThreadPool from multiprocessing.pool import Pool, ThreadPool
from pathlib import Path from pathlib import Path
from threading import Thread from threading import Thread
from urllib.parse import urlparse
from zipfile import ZipFile from zipfile import ZipFile
import cv2 import cv2
@ -301,7 +302,7 @@ class LoadStreams:
for i, s in enumerate(sources): # index, source for i, s in enumerate(sources): # index, source
# Start thread to read frames from video stream # Start thread to read frames from video stream
st = f'{i + 1}/{n}: {s}... ' st = f'{i + 1}/{n}: {s}... '
if 'youtube.com/' in s or 'youtu.be/' in s: # if source is YouTube video if urlparse(s).hostname in ('youtube.com', 'youtu.be'): # if source is YouTube video
check_requirements(('pafy', 'youtube_dl==2020.12.2')) check_requirements(('pafy', 'youtube_dl==2020.12.2'))
import pafy import pafy
s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL