Skip to content

Commit 00b4ff9

Browse files
Add explanation comments for tests for overlapped ZIP entries
1 parent 6784ef7 commit 00b4ff9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_zipfile/test_core.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,6 +2455,10 @@ def test_decompress_without_3rd_party_library(self):
24552455

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

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

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

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

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

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

0 commit comments

Comments
 (0)