bpo-41068: Fix read after write in zipfile for non-ASCII files names. (GH-21040)

This commit is contained in:
Serhiy Storchaka 2020-06-22 11:24:11 +03:00 committed by GitHub
parent c88239f864
commit 36ff513f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View File

@ -1600,6 +1600,11 @@ class OtherTests(unittest.TestCase):
self.assertEqual(zf.filelist[0].filename, "foo.txt") self.assertEqual(zf.filelist[0].filename, "foo.txt")
self.assertEqual(zf.filelist[1].filename, "\xf6.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): def test_exclusive_create_zip_file(self):
"""Test exclusive creating a new zipfile.""" """Test exclusive creating a new zipfile."""
unlink(TESTFN2) unlink(TESTFN2)

View File

@ -1534,7 +1534,7 @@ class ZipFile:
# strong encryption # strong encryption
raise NotImplementedError("strong encryption (flag bit 6)") raise NotImplementedError("strong encryption (flag bit 6)")
if zinfo.flag_bits & 0x800: if fheader[_FH_GENERAL_PURPOSE_FLAG_BITS] & 0x800:
# UTF-8 filename # UTF-8 filename
fname_str = fname.decode("utf-8") fname_str = fname.decode("utf-8")
else: else:

View File

@ -0,0 +1,2 @@
Fixed reading files with non-ASCII names from ZIP archive directly after
writing them.