@@ -292,6 +292,31 @@ def test_decompress_incorrect_length():
292
292
error .match ("Incorrect length of data produced" )
293
293
294
294
295
+ def test_decompress_on_long_input ():
296
+ # Ensure that a compressed payload with length bigger than 2**32 (ISIZE is
297
+ # overflown) can be decompressed. To avoid writing the whole uncompressed payload
298
+ # into memory, the test writes the compressed data in chunks. The payload consists
299
+ # almost exclusively of zeros to achieve an exteremely efficient compression rate,
300
+ # so that the compressed data also fits in memory.
301
+
302
+ buffered_stream = io .BytesIO ()
303
+ n = 20
304
+ block_size = 2 ** n
305
+ iterations = 2 ** (32 - n )
306
+ zeros_block = bytes (block_size )
307
+
308
+ # To avoid writing the whole compressed data, we will write the compressed data
309
+ with gzip_ng .open (buffered_stream , "wb" ) as gz :
310
+ for _ in range (iterations ):
311
+ gz .write (zeros_block )
312
+ gz .write (b"\x01 " * 123 )
313
+ buffered_stream .seek (0 )
314
+ with gzip_ng .open (buffered_stream , "rb" ) as gz :
315
+ for _ in range (iterations ):
316
+ assert zeros_block == gz .read (block_size )
317
+ assert gz .read () == b"\x01 " * 123
318
+
319
+
295
320
def test_decompress_incorrect_checksum ():
296
321
# Create a wrong checksum by using a non-default seed.
297
322
wrong_checksum = zlib .crc32 (DATA , 50 )
0 commit comments