@@ -9,29 +9,30 @@ def unzip(filename):
9
9
#BAD : This could write any file on the filesystem.
10
10
for entry in zipf :
11
11
shutil .move (entry , "/tmp/unpack/" )
12
-
12
+
13
13
def unzip1 (filename ):
14
14
with gzip .open (filename ) as zipf :
15
15
#BAD : This could write any file on the filesystem.
16
16
for entry in zipf :
17
17
shutil .copy2 (entry , "/tmp/unpack/" )
18
-
18
+
19
19
def unzip2 (filename ):
20
20
with bz2 .open (filename ) as zipf :
21
21
#BAD : This could write any file on the filesystem.
22
22
for entry in zipf :
23
23
shutil .copyfile (entry , "/tmp/unpack/" )
24
-
24
+
25
25
def unzip3 (filename ):
26
- with zipfile .ZipFile (filename ) as zipf :
26
+ zf = zipfile .ZipFile (filename )
27
+ filelist = zf .namelist ()
27
28
#BAD : This could write any file on the filesystem.
28
- for entry in zipf :
29
+ for filename in filelist :
29
30
shutil .copy (entry , "/tmp/unpack/" )
30
31
31
32
def 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 )
37
38
0 commit comments