@@ -9,29 +9,30 @@ def unzip(filename):
99 #BAD : This could write any file on the filesystem.
1010 for entry in zipf :
1111 shutil .move (entry , "/tmp/unpack/" )
12-
12+
1313def unzip1 (filename ):
1414 with gzip .open (filename ) as zipf :
1515 #BAD : This could write any file on the filesystem.
1616 for entry in zipf :
1717 shutil .copy2 (entry , "/tmp/unpack/" )
18-
18+
1919def unzip2 (filename ):
2020 with bz2 .open (filename ) as zipf :
2121 #BAD : This could write any file on the filesystem.
2222 for entry in zipf :
2323 shutil .copyfile (entry , "/tmp/unpack/" )
24-
24+
2525def unzip3 (filename ):
26- with zipfile .ZipFile (filename ) as zipf :
26+ zf = zipfile .ZipFile (filename )
27+ filelist = zf .namelist ()
2728 #BAD : This could write any file on the filesystem.
28- for entry in zipf :
29+ for filename in filelist :
2930 shutil .copy (entry , "/tmp/unpack/" )
3031
3132def unzip4 (filename ):
32- with zipfile .ZipFile (filename ) as zipf :
33- for entry in zipf :
34- with open ( entry , 'wb' ) as dstfile :
35- shutil . copyfileobj ( zipf , dstfile )
36-
33+ zf = zipfile .ZipFile (filename )
34+ filelist = zf . namelist ()
35+ for filename in filelist :
36+ with zf . open ( filename ) as srcf :
37+ shutil . copyfileobj ( srcf , dstfile )
3738
0 commit comments