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

Skip to content

Commit 23bd53a

Browse files
Update zipslip_good.py
1 parent 3b8c7e8 commit 23bd53a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import zipfile
2+
import tarfile
3+
import shutil
24

35
def unzip(filename, dir):
46
zf = zipfile.ZipFile(filename)
@@ -8,3 +10,11 @@ def unzip(filename, dir):
810
def unzip1(filename, dir):
911
zf = zipfile.ZipFile(filename)
1012
zf.extract(dir)
13+
14+
def unzip2(filename):
15+
with tarfile.open(filename) as tar:
16+
for entry in tar:
17+
#GOOD: Check that entry is safe
18+
if os.path.isabs(entry.name) or ".." in entry.name:
19+
raise ValueError("Illegal tar archive entry")
20+
shutil.copy(entry, "/tmp/unpack/")

0 commit comments

Comments
 (0)