summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-30 18:56:23 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-30 18:56:23 (GMT)
commit2f4453eff8296e6b5e57c237d47288d9a9842b00 (patch)
tree01394f25acffe7bc0a46055a5cd6fa65811c71df /Lib/test/test_tarfile.py
parent7984bff52a9952219a3c15b88ff6514244dd7498 (diff)
parenta89d22aff3fb1e67f8f08eac22b08a58dfa048a8 (diff)
downloadcpython-2f4453eff8296e6b5e57c237d47288d9a9842b00.zip
cpython-2f4453eff8296e6b5e57c237d47288d9a9842b00.tar.gz
cpython-2f4453eff8296e6b5e57c237d47288d9a9842b00.tar.bz2
Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar
file with compression before trying to open it without compression. Otherwise it had 50% chance failed with ignore_zeros=True.
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r--Lib/test/test_tarfile.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index d7785ce..619cbc0 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -3,6 +3,7 @@ import os
import io
from hashlib import md5
from contextlib import contextmanager
+from random import Random
import unittest
import unittest.mock
@@ -349,12 +350,17 @@ class CommonReadTest(ReadTest):
def test_ignore_zeros(self):
# Test TarFile's ignore_zeros option.
+ # generate 512 pseudorandom bytes
+ data = Random(0).getrandbits(512*8).to_bytes(512, 'big')
for char in (b'\0', b'a'):
# Test if EOFHeaderError ('\0') and InvalidHeaderError ('a')
# are ignored correctly.
with self.open(tmpname, "w") as fobj:
fobj.write(char * 1024)
- fobj.write(tarfile.TarInfo("foo").tobuf())
+ tarinfo = tarfile.TarInfo("foo")
+ tarinfo.size = len(data)
+ fobj.write(tarinfo.tobuf())
+ fobj.write(data)
tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
try: