diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-12 14:51:20 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-12 14:51:20 (GMT) |
| commit | 6464d5ffdc6ee54f023c6230f1633debf183815f (patch) | |
| tree | 3efb844f24e15fcd80151ac2d8e9a56e5ed92f9a /Lib/test | |
| parent | 0b9489d21daec1f5f45a95194423724836192edd (diff) | |
| download | cpython-6464d5ffdc6ee54f023c6230f1633debf183815f.zip cpython-6464d5ffdc6ee54f023c6230f1633debf183815f.tar.gz cpython-6464d5ffdc6ee54f023c6230f1633debf183815f.tar.bz2 | |
Issue #9837: The read() method of ZipExtFile objects (as returned by
ZipFile.open()) could return more bytes than requested.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_zipfile.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 82b4061..380e63b 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -939,6 +939,26 @@ class OtherTests(unittest.TestCase): def test_read_with_bad_crc_deflated(self): self.check_read_with_bad_crc(zipfile.ZIP_DEFLATED) + def check_read_return_size(self, compression): + # Issue #9837: ZipExtFile.read() shouldn't return more bytes + # than requested. + for test_size in (1, 4095, 4096, 4097, 16384): + file_size = test_size + 1 + junk = b''.join(struct.pack('B', randint(0, 255)) + for x in range(file_size)) + with zipfile.ZipFile(io.BytesIO(), "w", compression) as zipf: + zipf.writestr('foo', junk) + with zipf.open('foo', 'r') as fp: + buf = fp.read(test_size) + self.assertEqual(len(buf), test_size) + + def test_read_return_size_stored(self): + self.check_read_return_size(zipfile.ZIP_STORED) + + @skipUnless(zlib, "requires zlib") + def test_read_return_size_deflated(self): + self.check_read_return_size(zipfile.ZIP_DEFLATED) + def tearDown(self): unlink(TESTFN) unlink(TESTFN2) |
