diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-12 14:55:22 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-12 14:55:22 (GMT) |
commit | 1052e3993bea30b5a2901ce4f480297a8299184c (patch) | |
tree | 6693c8e5fe19d14a61e20c14c3362249232bc883 /Lib | |
parent | ee906192b50d078bac65ef2f18a53318169e7992 (diff) | |
download | cpython-1052e3993bea30b5a2901ce4f480297a8299184c.zip cpython-1052e3993bea30b5a2901ce4f480297a8299184c.tar.gz cpython-1052e3993bea30b5a2901ce4f480297a8299184c.tar.bz2 |
Merged revisions 84737 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
Only the tests are merged, 3.1 doesn't exhibit the issue.
........
r84737 | antoine.pitrou | 2010-09-12 16:51:20 +0200 (dim., 12 sept. 2010) | 4 lines
Issue #9837: The read() method of ZipExtFile objects (as returned by
ZipFile.open()) could return more bytes than requested.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_zipfile.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 474ec58..0e67dbd 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -879,6 +879,29 @@ 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)) + zipf = zipfile.ZipFile(io.BytesIO(), "w", compression) + try: + zipf.writestr('foo', junk) + fp = zipf.open('foo', 'r') + buf = fp.read(test_size) + self.assertEqual(len(buf), test_size) + finally: + zipf.close() + + def test_read_return_size_stored(self): + self.check_read_return_size(zipfile.ZIP_STORED) + + if zlib: + def test_read_return_size_deflated(self): + self.check_read_return_size(zipfile.ZIP_DEFLATED) + def tearDown(self): support.unlink(TESTFN) support.unlink(TESTFN2) |