diff options
author | Martin Panter <vadmium+py@gmail.com> | 2015-11-20 08:13:35 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2015-11-20 08:13:35 (GMT) |
commit | e99e97762cc75ad94056275ddcae9c84d63a3412 (patch) | |
tree | f16040197bf0122ce6aded03018b4ee6fee03679 /Lib/test/test_gzip.py | |
parent | d13cade3817cf452b7c98e9df96b15c6da68201a (diff) | |
download | cpython-e99e97762cc75ad94056275ddcae9c84d63a3412.zip cpython-e99e97762cc75ad94056275ddcae9c84d63a3412.tar.gz cpython-e99e97762cc75ad94056275ddcae9c84d63a3412.tar.bz2 |
Issue #25626: Change zlib to accept Py_ssize_t and cap to UINT_MAX
The underlying zlib library stores sizes in “unsigned int”. The corresponding
Python parameters are all sizes of buffers filled in by zlib, so it is okay
to reduce higher values to the UINT_MAX internal cap. OverflowError is still
raised for sizes that do not fit in Py_ssize_t.
Sizes are now limited to Py_ssize_t rather than unsigned long, because Python
byte strings cannot be larger than Py_ssize_t. Previously this could result
in a SystemError on 32-bit platforms.
This resolves a regression in the gzip module when reading more than UINT_MAX
or LONG_MAX bytes in one call, introduced by revision 62723172412c.
Diffstat (limited to 'Lib/test/test_gzip.py')
-rw-r--r-- | Lib/test/test_gzip.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index d8408e1..3c51673 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -3,6 +3,7 @@ import unittest from test import support +from test.support import bigmemtest, _4G import os import io import struct @@ -116,6 +117,14 @@ class TestGzip(BaseTest): self.assertEqual(f.tell(), nread) self.assertEqual(b''.join(blocks), data1 * 50) + @bigmemtest(size=_4G, memuse=1) + def test_read_large(self, size): + # Read chunk size over UINT_MAX should be supported, despite zlib's + # limitation per low-level call + compressed = gzip.compress(data1, compresslevel=1) + f = gzip.GzipFile(fileobj=io.BytesIO(compressed), mode='rb') + self.assertEqual(f.read(size), data1) + def test_io_on_closed_object(self): # Test that I/O operations on closed GzipFile objects raise a # ValueError, just like the corresponding functions on file objects. |