diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index ab1995e91286e68..5c9a6fc980d3c95 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -4935,6 +4935,70 @@ class ZstdBoundedDecompressTests(AbstractBoundedDecompressTests, compression = zipfile.ZIP_ZSTANDARD +@requires_zstd() +class ZstdMultipleFramesTests(unittest.TestCase): + # A zstd stream may consist of several concatenated frames (RFC 8878, + # section 3.1), as written by multi-threaded or streaming compressors. + part1 = b'first frame ' * 1000 + part2 = b'second frame ' * 1000 + + def make_zip(self, member_data, content): + # Store member_data, then relabel the member as Zstandard-compressed + # with the CRC and size of the decompressed content. + buf = io.BytesIO() + with zipfile.ZipFile(buf, 'w') as zf: + zf.writestr(zipfile.ZipInfo('a'), member_data) + data = bytearray(buf.getvalue()) + crc = zipfile.crc32(content) + cd = data.rindex(zipfile.stringCentralDir) + # Offsets of the method, CRC-32 and uncompressed size fields in the + # local file header and in the central directory record. + for method, crc_pos, size_pos in ((8, 14, 22), + (cd + 10, cd + 16, cd + 24)): + struct.pack_into('