Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,11 @@ def test_write_unicode_filenames(self):
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)
Expand Down
2 changes: 1 addition & 1 deletion Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ def open(self, name, mode="r", pwd=None, *, force_zip64=False):
# 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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed reading files with non-ASCII names from ZIP archive directly after
writing them.