2525 display:block;
2626}
2727"""
28+ tmp_upload_folder = "/tmp/gradio/"
2829
2930# create a FastAPI app
3031app = FastAPI ()
@@ -122,11 +123,14 @@ def http_bot(state, request: gr.Request):
122123 video_file = metadata ["source_video" ]
123124 state .video_file = os .path .join (static_dir , metadata ["source_video" ])
124125 state .time_of_frame_ms = metadata ["time_of_frame_ms" ]
125- splited_video_path = split_video (
126- state .video_file , state .time_of_frame_ms , tmp_dir , f"{ state .time_of_frame_ms } __{ video_file } "
127- )
126+ try :
127+ splited_video_path = split_video (
128+ state .video_file , state .time_of_frame_ms , tmp_dir , f"{ state .time_of_frame_ms } __{ video_file } "
129+ )
130+ except :
131+ print (f"video { state .video_file } does not exist in UI host!" )
132+ splited_video_path = None
128133 state .split_video = splited_video_path
129- print (splited_video_path )
130134 else :
131135 raise requests .exceptions .RequestException
132136 except requests .exceptions .RequestException as e :
@@ -143,9 +147,19 @@ def http_bot(state, request: gr.Request):
143147
144148def ingest_video_gen_transcript (filepath , request : gr .Request ):
145149 yield (gr .Textbox (visible = True , value = "Please wait for ingesting your uploaded video into database..." ))
146- basename = os .path .basename (filepath )
150+ verified_filepath = os .path .normpath (filepath )
151+ if not verified_filepath .startswith (tmp_upload_folder ):
152+ print ("Found malicious video file name!" )
153+ yield (
154+ gr .Textbox (
155+ visible = True ,
156+ value = "Your uploaded video's file name has special characters that are not allowed. Please consider update the video file name!" ,
157+ )
158+ )
159+ return
160+ basename = os .path .basename (verified_filepath )
147161 dest = os .path .join (static_dir , basename )
148- shutil .copy (filepath , dest )
162+ shutil .copy (verified_filepath , dest )
149163 print ("Done copy uploaded file to static folder!" )
150164 headers = {
151165 # 'Content-Type': 'multipart/form-data'
@@ -185,9 +199,19 @@ def ingest_video_gen_transcript(filepath, request: gr.Request):
185199
186200def ingest_video_gen_caption (filepath , request : gr .Request ):
187201 yield (gr .Textbox (visible = True , value = "Please wait for ingesting your uploaded video into database..." ))
188- basename = os .path .basename (filepath )
202+ verified_filepath = os .path .normpath (filepath )
203+ if not verified_filepath .startswith (tmp_upload_folder ):
204+ print ("Found malicious video file name!" )
205+ yield (
206+ gr .Textbox (
207+ visible = True ,
208+ value = "Your uploaded video's file name has special characters that are not allowed. Please consider update the video file name!" ,
209+ )
210+ )
211+ return
212+ basename = os .path .basename (verified_filepath )
189213 dest = os .path .join (static_dir , basename )
190- shutil .copy (filepath , dest )
214+ shutil .copy (verified_filepath , dest )
191215 print ("Done copy uploaded file to static folder!" )
192216 headers = {
193217 # 'Content-Type': 'multipart/form-data'
0 commit comments