From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 22 Jun 2020 08:46:11 +0000 (-0700) Subject: bpo-41068: Fix read after write in zipfile for non-ASCII files names. (GH-21040) X-Git-Tag: v3.9.0b4~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c916c48afc02c26a50843c7b381a2b567bb72e46;p=thirdparty%2FPython%2Fcpython.git bpo-41068: Fix read after write in zipfile for non-ASCII files names. (GH-21040) (cherry picked from commit 36ff513f82e372ed3cea0bf7cbdf15a1ef6dab9e) Co-authored-by: Serhiy Storchaka --- diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index c9ca1ddaafe1..b7bc218d17a3 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -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) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 8903d6a42ee4..915698f9e058 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -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 index 000000000000..20580c7886fa --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-22-10-25-39.bpo-41068._bX2BW.rst @@ -0,0 +1,2 @@ +Fixed reading files with non-ASCII names from ZIP archive directly after +writing them.