Skip to content

Commit 100c726

Browse files
Add explanation comments for tests for overlapped ZIP entries (GH-137152)
1 parent 706fdda commit 100c726

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
@@ -2531,6 +2531,10 @@ def test_decompress_without_3rd_party_library(self):
25312531

25322532
@requires_zlib()
25332533
def test_full_overlap_different_names(self):
2534+
# The ZIP file contains two central directory entries with
2535+
# different names which refer to the same local header.
2536+
# The name of the local header matches the name of the first
2537+
# central directory entry.
25342538
data = (
25352539
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xa0lH\x05\xe2\x1e'
25362540
b'8\xbb\x10\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00b\xed'
@@ -2560,6 +2564,10 @@ def test_full_overlap_different_names(self):
25602564

25612565
@requires_zlib()
25622566
def test_full_overlap_different_names2(self):
2567+
# The ZIP file contains two central directory entries with
2568+
# different names which refer to the same local header.
2569+
# The name of the local header matches the name of the second
2570+
# central directory entry.
25632571
data = (
25642572
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xa0lH\x05\xe2\x1e'
25652573
b'8\xbb\x10\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00a\xed'
@@ -2591,6 +2599,8 @@ def test_full_overlap_different_names2(self):
25912599

25922600
@requires_zlib()
25932601
def test_full_overlap_same_name(self):
2602+
# The ZIP file contains two central directory entries with
2603+
# the same name which refer to the same local header.
25942604
data = (
25952605
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xa0lH\x05\xe2\x1e'
25962606
b'8\xbb\x10\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00a\xed'
@@ -2623,6 +2633,8 @@ def test_full_overlap_same_name(self):
26232633

26242634
@requires_zlib()
26252635
def test_quoted_overlap(self):
2636+
# The ZIP file contains two files. The second local header
2637+
# is contained in the range of the first file.
26262638
data = (
26272639
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xa0lH\x05Y\xfc'
26282640
b'8\x044\x00\x00\x00(\x04\x00\x00\x01\x00\x00\x00a\x00'
@@ -2654,6 +2666,7 @@ def test_quoted_overlap(self):
26542666

26552667
@requires_zlib()
26562668
def test_overlap_with_central_dir(self):
2669+
# The local header offset is equal to the central directory offset.
26572670
data = (
26582671
b'PK\x01\x02\x14\x03\x14\x00\x00\x00\x08\x00G_|Z'
26592672
b'\xe2\x1e8\xbb\x0b\x00\x00\x00\t\x04\x00\x00\x01\x00\x00\x00'
@@ -2668,11 +2681,15 @@ def test_overlap_with_central_dir(self):
26682681
self.assertEqual(zi.header_offset, 0)
26692682
self.assertEqual(zi.compress_size, 11)
26702683
self.assertEqual(zi.file_size, 1033)
2684+
# Found central directory signature PK\x01\x02 instead of
2685+
# local header signature PK\x03\x04.
26712686
with self.assertRaisesRegex(zipfile.BadZipFile, 'Bad magic number'):
26722687
zipf.read('a')
26732688

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

0 commit comments

Comments
 (0)