]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41068: Fix read after write in zipfile for non-ASCII files names. (GH-21040)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 22 Jun 2020 08:24:11 +0000 (11:24 +0300)
committerGitHub <noreply@github.com>
Mon, 22 Jun 2020 08:24:11 +0000 (11:24 +0300)
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 c9ca1ddaafe1918e57b02eb7c06c46eda81b6792..b7bc218d17a3d966171cdd98c5750720b4f78fed 100644 (file)
@@ -1600,6 +1600,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 8903d6a42ee4ebba3c5b6847689bf9ca05d1c3af..915698f9e0588936f7adb1b0394860819fad8f73 100644 (file)
@@ -1534,7 +1534,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.