Skip to content

Commit b68e70f

Browse files
committed
SQUASHME: Added comments to tests
1 parent 9b66476 commit b68e70f

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

Lib/test/test_zipfile/test_core.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,25 @@ def test_generated_valid_zip64_extra(self):
10821082

10831083
def test_force_zip64(self):
10841084
"""Test that forcing zip64 extensions correctly notes this in the zip file"""
1085+
1086+
# GH-103861 describes an issue where forcing a small file to use zip64
1087+
# extensions would add a zip64 extra record, but not change the data
1088+
# sizes to 0xFFFFFFFF to indicate to the extractor that the zip64
1089+
# record should be read. Additionally, it would not set the required
1090+
# version to indicate that zip64 extensions are required to extract it.
1091+
# This test replicates the situation and reads the raw data to specifically ensure:
1092+
# - The required extract version is always >= ZIP64_VERSION
1093+
# - The compressed and uncompressed size in the file headers are both
1094+
# 0xFFFFFFFF (ie. point to zip64 record)
1095+
# - The zip64 record is provided and has the correct sizes in it
1096+
# Other aspects of the zip are checked as well, but verifying the above is the main goal.
1097+
# Because this is hard to verify by parsing the data as a zip, the raw
1098+
# bytes are checked to ensure that they line up with the zip spec.
1099+
# The spec for this can be found at: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
1100+
# The relevent sections for this test are:
1101+
# - 4.3.7 for local file header
1102+
# - 4.5.3 for zip64 extra field
1103+
10851104
data = io.BytesIO()
10861105
with zipfile.ZipFile(data, mode="w", allowZip64=True) as zf:
10871106
with zf.open("text.txt", mode="w", force_zip64=True) as zi:
@@ -1141,6 +1160,19 @@ def make_zip(fp):
11411160
def test_unseekable_zip_known_filesize(self):
11421161
"""Test that creating a zip without seeking will use zip64 extensions if the file size is provided up-front"""
11431162

1163+
# This test ensures that the zip will use a zip64 data descriptor (same
1164+
# as a regular data descriptor except the sizes are 8 bytes instead of
1165+
# 4) record to communicate the size of a file if the zip is being
1166+
# written to an unseekable stream.
1167+
# Because this sort of thing is hard to verify by parsing the data back
1168+
# in as a zip, this test looks at the raw bytes created to ensure that
1169+
# the correct data has been generated.
1170+
# The spec for this can be found at: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
1171+
# The relevent sections for this test are:
1172+
# - 4.3.7 for local file header
1173+
# - 4.3.9 for the data descriptor
1174+
# - 4.5.3 for zip64 extra field
1175+
11441176
file_size = zipfile.ZIP64_LIMIT + 1
11451177

11461178
def make_zip(fp):
@@ -1160,7 +1192,7 @@ def make_zip(fp):
11601192
cd_sig
11611193
) = struct.unpack("<4sBBHH8xIIHH8shhQQ{}x4s".format(file_size), seekable_data[:62 + file_size])
11621194

1163-
self.assertEqual(header, b"PK\x03\x04")
1195+
self.assertEqual(header, b"PK\x03\x04") # local file header
11641196
self.assertGreaterEqual(vers, zipfile.ZIP64_VERSION) # requires zip64 to extract
11651197
self.assertEqual(os, 0) # compatible with MS-DOS
11661198
self.assertEqual(flags, 0) # no flags set
@@ -1183,7 +1215,7 @@ def make_zip(fp):
11831215
dd_header, dd_usize, dd_csize, cd_sig
11841216
) = struct.unpack("<4sBBHH8xIIHH8shhQQ{}x4s4xQQ4s".format(file_size), unseekable_data[:86 + file_size])
11851217

1186-
self.assertEqual(header, b"PK\x03\x04")
1218+
self.assertEqual(header, b"PK\x03\x04") # local file header
11871219
self.assertGreaterEqual(vers, zipfile.ZIP64_VERSION) # requires zip64 to extract
11881220
self.assertEqual(os, 0) # compatible with MS-DOS
11891221
self.assertEqual("{:b}".format(flags), "1000") # streaming flag set

0 commit comments

Comments
 (0)