Skip to content

Add explanation comments for tests for overlapped ZIP entries #137152

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions Lib/test/test_zipfile/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2455,6 +2455,10 @@ def test_decompress_without_3rd_party_library(self):

@requires_zlib()
def test_full_overlap_different_names(self):
# The ZIP file contains two central directory entries with
# different names which refer to the same local header.
# The name of the local header matches the name of the first
# central directory entry.
data = (
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xa0lH\x05\xe2\x1e'
b'8\xbb\x10\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00b\xed'
Expand Down Expand Up @@ -2484,6 +2488,10 @@ def test_full_overlap_different_names(self):

@requires_zlib()
def test_full_overlap_different_names2(self):
# The ZIP file contains two central directory entries with
# different names which refer to the same local header.
# The name of the local header matches the name of the second
# central directory entry.
data = (
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xa0lH\x05\xe2\x1e'
b'8\xbb\x10\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00a\xed'
Expand Down Expand Up @@ -2515,6 +2523,8 @@ def test_full_overlap_different_names2(self):

@requires_zlib()
def test_full_overlap_same_name(self):
# The ZIP file contains two central directory entries with
# the same name which refer to the same local header.
data = (
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xa0lH\x05\xe2\x1e'
b'8\xbb\x10\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00a\xed'
Expand Down Expand Up @@ -2547,6 +2557,8 @@ def test_full_overlap_same_name(self):

@requires_zlib()
def test_quoted_overlap(self):
# The ZIP file contains two files. The second local header
# is contained in the range of the first file.
data = (
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xa0lH\x05Y\xfc'
b'8\x044\x00\x00\x00(\x04\x00\x00\x01\x00\x00\x00a\x00'
Expand Down Expand Up @@ -2578,6 +2590,7 @@ def test_quoted_overlap(self):

@requires_zlib()
def test_overlap_with_central_dir(self):
# The local header offset is equal to the central directory offset.
data = (
b'PK\x01\x02\x14\x03\x14\x00\x00\x00\x08\x00G_|Z'
b'\xe2\x1e8\xbb\x0b\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00'
Expand All @@ -2592,11 +2605,15 @@ def test_overlap_with_central_dir(self):
self.assertEqual(zi.header_offset, 0)
self.assertEqual(zi.compress_size, 11)
self.assertEqual(zi.file_size, 1033)
# Found central directory signature PK\x01\x02 instead of
# local header signature PK\x03\x04.
with self.assertRaisesRegex(zipfile.BadZipFile, 'Bad magic number'):
zipf.read('a')

@requires_zlib()
def test_overlap_with_archive_comment(self):
# The local header is written after the central directory,
# in the archive comment.
data = (
b'PK\x01\x02\x14\x03\x14\x00\x00\x00\x08\x00G_|Z'
b'\xe2\x1e8\xbb\x0b\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00'
Expand Down
Loading