Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8dea724

Browse files
Update zipslip_bad.py
1 parent b5f1e9d commit 8dea724

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

  • python/ql/test/experimental/query-tests/Security/CWE-022

python/ql/test/experimental/query-tests/Security/CWE-022/zipslip_bad.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,33 @@
55
import zipfile
66

77
def unzip(filename):
8-
9-
with tarfile.open(filename) as zipf:
8+
with tarfile.open(filename) as zipf:
109
#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/")
1312

1413
def unzip1(filename):
15-
with gzip.open(filename) as zipf:
14+
with gzip.open(filename) as zipf:
1615
#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/")
1918

2019
def unzip2(filename):
21-
with bz2.open(filename) as zipf:
20+
with bz2.open(filename) as zipf:
2221
#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/")
2524

2625
def unzip3(filename):
27-
with zipfile.ZipFile(filename) as zipf:
26+
with zipfile.ZipFile(filename) as zipf:
2827
#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/")
3130

3231
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)
3736

3837

0 commit comments

Comments
 (0)