]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41068: Fix read after write in zipfile for non-ASCII files names. (GH-21040)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 22 Jun 2020 08:40:05 +0000 (01:40 -0700)
committerGitHub <noreply@github.com>
Mon, 22 Jun 2020 08:40:05 +0000 (01:40 -0700)
(cherry picked from commit 36ff513f82e372ed3cea0bf7cbdf15a1ef6dab9e)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst [new file with mode: 0644]

index 28e62dc5c61c503dda70f37295858da7b6e5eeec..e2e37a177041855671f67f46137f4333370ec727 100644 (file)
@@ -1589,6 +1589,11 @@ class OtherTests(unittest.TestCase):
             self.assertEqual(zf.filelist[0].filename, "foo.txt")
             self.assertEqual(zf.filelist[1].filename, "\xf6.txt")
 
+    def test_read_after_write_unicode_filenames(self):
+        with zipfile.ZipFile(TESTFN2, 'w') as zipfp:
+            zipfp.writestr('приклад', b'sample')
+            self.assertEqual(zipfp.read('приклад'), b'sample')
+
     def test_exclusive_create_zip_file(self):
         """Test exclusive creating a new zipfile."""
         unlink(TESTFN2)
index f7a2a2e8b8ab9a91b62df1d8e2dfb92a8ebafa99..73e89666309ffec1cbbb9d8444dfde139b3c264e 100644 (file)
@@ -1546,7 +1546,7 @@ class ZipFile:
                 # strong encryption
                 raise NotImplementedError("strong encryption (flag bit 6)")
 
-            if zinfo.flag_bits & 0x800:
+            if fheader[_FH_GENERAL_PURPOSE_FLAG_BITS] & 0x800:
                 # UTF-8 filename
                 fname_str = fname.decode("utf-8")
             else:
diff --git a/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst b/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst
new file mode 100644 (file)
index 0000000..20580c7
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed reading files with non-ASCII names from ZIP archive directly after
+writing them.