summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/tarfile.py2
-rw-r--r--Lib/test/test_tarfile.py12
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 42100e9..b47015f 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2339,6 +2339,8 @@ class TarFile(object):
# Advance the file pointer.
if self.offset != self.fileobj.tell():
+ if self.offset == 0:
+ return None
self.fileobj.seek(self.offset - 1)
if not self.fileobj.read(1):
raise ReadError("unexpected end of data")
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 0868d5d..2139320 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -734,6 +734,18 @@ class MiscReadTestBase(CommonReadTest):
with self.assertRaises(tarfile.ReadError):
tarfile.open(self.tarname)
+ def test_next_on_empty_tarfile(self):
+ fd = io.BytesIO()
+ tf = tarfile.open(fileobj=fd, mode="w")
+ tf.close()
+
+ fd.seek(0)
+ with tarfile.open(fileobj=fd, mode="r|") as tf:
+ self.assertEqual(tf.next(), None)
+
+ fd.seek(0)
+ with tarfile.open(fileobj=fd, mode="r") as tf:
+ self.assertEqual(tf.next(), None)
class MiscReadTest(MiscReadTestBase, unittest.TestCase):
test_fail_comp = None