summaryrefslogtreecommitdiff
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2009-03-22 20:34:29 +0000
committerLars Gustäbel <lars@gustaebel.de>2009-03-22 20:34:29 +0000
commit53e10091c2a42bfc673ad175354f78122494a8a5 (patch)
tree540982a015d68885f08b1ab079971657b9178fa5 /Lib/test/test_tarfile.py
parent4c436deb6e6c561c2fde4880df6b6957cc9d262d (diff)
downloadcpython-53e10091c2a42bfc673ad175354f78122494a8a5.tar.gz
Merged revisions 70523 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70523 | lars.gustaebel | 2009-03-22 21:09:33 +0100 (Sun, 22 Mar 2009) | 5 lines Issue #5068: Fixed the tarfile._BZ2Proxy.read() method that would loop forever on incomplete input. That caused tarfile.open() to hang when used with mode 'r' or 'r:bz2' and a fileobj argument that contained no data or partial bzip2 compressed data. ........
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r--Lib/test/test_tarfile.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index affbeeb6c2..f4c0035985 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -1121,6 +1121,30 @@ class Bz2WriteTest(WriteTest):
class Bz2StreamWriteTest(StreamWriteTest):
mode = "w|bz2"
+class Bz2PartialReadTest(unittest.TestCase):
+ # Issue5068: The _BZ2Proxy.read() method loops forever
+ # on an empty or partial bzipped file.
+
+ def _test_partial_input(self, mode):
+ class MyBytesIO(io.BytesIO):
+ hit_eof = False
+ def read(self, n):
+ if self.hit_eof:
+ raise AssertionError("infinite loop detected in tarfile.open()")
+ self.hit_eof = self.tell() == len(self.getvalue())
+ return super(MyBytesIO, self).read(n)
+
+ data = bz2.compress(tarfile.TarInfo("foo").tobuf())
+ for x in range(len(data) + 1):
+ tarfile.open(fileobj=MyBytesIO(data[:x]), mode=mode)
+
+ def test_partial_input(self):
+ self._test_partial_input("r")
+
+ def test_partial_input_bz2(self):
+ self._test_partial_input("r:bz2")
+
+
def test_main():
if not os.path.exists(TEMPDIR):
os.mkdir(TEMPDIR)
@@ -1178,6 +1202,7 @@ def test_main():
Bz2StreamReadTest,
Bz2WriteTest,
Bz2StreamWriteTest,
+ Bz2PartialReadTest,
]
try: