|
5 | 5 | import zipfile |
6 | 6 |
|
7 | 7 | def unzip(filename): |
8 | | - |
9 | | - with tarfile.open(filename) as zipf: |
| 8 | + with tarfile.open(filename) as zipf: |
10 | 9 | #BAD : This could write any file on the filesystem. |
11 | | - for entry in zipf: |
12 | | - shutil.move(entry, "/tmp/unpack/") |
| 10 | + for entry in zipf: |
| 11 | + shutil.move(entry, "/tmp/unpack/") |
13 | 12 |
|
14 | 13 | def unzip1(filename): |
15 | | - with gzip.open(filename) as zipf: |
| 14 | + with gzip.open(filename) as zipf: |
16 | 15 | #BAD : This could write any file on the filesystem. |
17 | | - for entry in zipf: |
18 | | - shutil.copy2(entry, "/tmp/unpack/") |
| 16 | + for entry in zipf: |
| 17 | + shutil.copy2(entry, "/tmp/unpack/") |
19 | 18 |
|
20 | 19 | def unzip2(filename): |
21 | | - with bz2.open(filename) as zipf: |
| 20 | + with bz2.open(filename) as zipf: |
22 | 21 | #BAD : This could write any file on the filesystem. |
23 | | - for entry in zipf: |
24 | | - shutil.copyfile(entry, "/tmp/unpack/") |
| 22 | + for entry in zipf: |
| 23 | + shutil.copyfile(entry, "/tmp/unpack/") |
25 | 24 |
|
26 | 25 | def unzip3(filename): |
27 | | - with zipfile.ZipFile(filename) as zipf: |
| 26 | + with zipfile.ZipFile(filename) as zipf: |
28 | 27 | #BAD : This could write any file on the filesystem. |
29 | | - for entry in zipf: |
30 | | - shutil.copy(entry, "/tmp/unpack/") |
| 28 | + for entry in zipf: |
| 29 | + shutil.copy(entry, "/tmp/unpack/") |
31 | 30 |
|
32 | 31 | def unzip4(filename): |
33 | | - with zipfile.ZipFile(filename) as zipf: |
34 | | - for entry in zipf: |
35 | | - with open(entry, 'wb') as dstfile: |
36 | | - shutil.copyfileobj(zipf, dstfile) |
| 32 | + with zipfile.ZipFile(filename) as zipf: |
| 33 | + for entry in zipf: |
| 34 | + with open(entry, 'wb') as dstfile: |
| 35 | + shutil.copyfileobj(zipf, dstfile) |
37 | 36 |
|
38 | 37 |
|
0 commit comments