]> granicus.if.org Git - python/commitdiff
Preserve backslashes in malicious zip files for testing issue #6972.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 2 Feb 2013 16:34:57 +0000 (18:34 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 2 Feb 2013 16:34:57 +0000 (18:34 +0200)
Lib/test/test_zipfile.py

index f535e56e9b9690675c6cb0834bea5e0d8f4ee7cd..b5fff7fa7231ba3463793780afa71adb391fd0b1 100644 (file)
@@ -461,12 +461,17 @@ class TestsWithSourceFile(unittest.TestCase):
             hacknames.extend([
                 ('//foo/bar', 'foo/bar'),
                 ('../../foo../../ba..r', 'foo../ba..r'),
+                (r'foo/..\bar', r'foo/..\bar'),
             ])
 
         for arcname, fixedname in hacknames:
             content = b'foobar' + arcname.encode()
             with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_STORED) as zipfp:
-                zipfp.writestr(arcname, content)
+                zinfo = zipfile.ZipInfo()
+                # preserve backslashes
+                zinfo.filename = arcname
+                zinfo.external_attr = 0o600 << 16
+                zipfp.writestr(zinfo, content)
 
             targetpath = os.path.join('target', 'subdir', 'subsub')
             correctfile = os.path.join(targetpath, *fixedname.split('/'))