File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1111from os .path import join as pjoin
1212import uuid
1313import base64
14+ import tarfile
1415
1516
1617class DatasetHandler (BaseHandler ):
@@ -21,6 +22,11 @@ def post(self):
2122 return self .error ('No tar file uploaded' )
2223
2324 zipfile = data ['tarFile' ]
25+ tarball_content_type_str = 'data:application/gzip;base64,'
26+
27+ if not zipfile ['body' ].startswith (tarball_content_type_str ):
28+ return self .error ('Invalid tar file - please ensure file is gzip '
29+ 'format.' )
2430
2531 if zipfile ['name' ] == '' :
2632 return self .error ('Empty tar file uploaded' )
@@ -34,7 +40,13 @@ def post(self):
3440
3541 with open (zipfile_path , 'wb' ) as f :
3642 f .write (base64 .b64decode (
37- zipfile ['body' ].replace ('data:application/gzip;base64,' , '' )))
43+ zipfile ['body' ].replace (tarball_content_type_str , '' )))
44+ try :
45+ tarfile .open (zipfile_path )
46+ except tarfile .ReadError :
47+ os .remove (zipfile_path )
48+ return self .error ('Invalid tar file - please ensure file is gzip '
49+ 'format.' )
3850
3951 # Header file is optional for unlabled data w/o metafeatures
4052 if 'headerFile' in data :
You can’t perform that action at this time.
0 commit comments