diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2011-12-06 13:07:09 +0100 |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2011-12-06 13:07:09 +0100 |
commit | 9a38863d8ce5444be29d2e20341b28147b94f33a (patch) | |
tree | bc8d512e0e17b5b3488a20ccd3bc781e622285aa /Lib/test/test_tarfile.py | |
parent | 22da68b1b034beac7867058f37a2fc9924f247f3 (diff) | |
download | cpython-git-9a38863d8ce5444be29d2e20341b28147b94f33a.tar.gz |
Correctly detect bzip2 compressed streams with blocksizes other than 900k.
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r-- | Lib/test/test_tarfile.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 6962f8e2d7..49d2d07d90 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -440,6 +440,23 @@ class DetectReadTest(unittest.TestCase): def test_detect_fileobj(self): self._test_modes(self._testfunc_fileobj) + def test_detect_stream_bz2(self): + # Originally, tarfile's stream detection looked for the string + # "BZh91" at the start of the file. This is incorrect because + # the '9' represents the blocksize (900kB). If the file was + # compressed using another blocksize autodetection fails. + if not bz2: + return + + with open(tarname, "rb") as fobj: + data = fobj.read() + + # Compress with blocksize 100kB, the file starts with "BZh11". + with bz2.BZ2File(tmpname, "wb", compresslevel=1) as fobj: + fobj.write(data) + + self._testfunc_file(tmpname, "r|*") + class MemberReadTest(ReadTest): |