Commit 9a38863d authored by Lars Gustäbel's avatar Lars Gustäbel

Correctly detect bzip2 compressed streams with blocksizes other than 900k.

parent 22da68b1
...@@ -627,7 +627,7 @@ class _StreamProxy(object): ...@@ -627,7 +627,7 @@ class _StreamProxy(object):
def getcomptype(self): def getcomptype(self):
if self.buf.startswith("\037\213\010"): if self.buf.startswith("\037\213\010"):
return "gz" return "gz"
if self.buf.startswith("BZh91"): if self.buf[0:3] == "BZh" and self.buf[4:10] == "1AY&SY":
return "bz2" return "bz2"
return "tar" return "tar"
......
...@@ -440,6 +440,23 @@ class DetectReadTest(unittest.TestCase): ...@@ -440,6 +440,23 @@ class DetectReadTest(unittest.TestCase):
def test_detect_fileobj(self): def test_detect_fileobj(self):
self._test_modes(self._testfunc_fileobj) 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): class MemberReadTest(ReadTest):
......
...@@ -79,6 +79,9 @@ Core and Builtins ...@@ -79,6 +79,9 @@ Core and Builtins
Library Library
------- -------
- tarfile.py: Correctly detect bzip2 compressed streams with blocksizes
other than 900k.
- Issue #13439: Fix many errors in turtle docstrings. - Issue #13439: Fix many errors in turtle docstrings.
- Issue #12856: Ensure child processes do not inherit the parent's random - Issue #12856: Ensure child processes do not inherit the parent's random
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment