[New-bugs-announce] [issue46922] tarfile.TarFile.next() crashes on empty tar files

progval report at bugs.python.org
Fri Mar 4 11:43:29 EST 2022


New submission from progval <progval+bugs.python.org at progval.net>:

Hi,

I found two related bugs when calling tarfile.TarFile.next() on an empty tar file, both when trying to seek when it should not:

import io
import tarfile

# Create a tarball with no member:
fd = io.BytesIO()
with tarfile.open(fileobj=fd, mode="w") as tf:
    pass

# read in stream mode:
fd.seek(0)
with tarfile.open(fileobj=fd, mode="r|") as tf:
    print(tf.next())   # tarfile.StreamError: seeking backwards is not allowed

# read in normal mode:
fd.seek(0)
with tarfile.open(fileobj=fd, mode="r") as tf:
    print(tf.next())  # ValueError: negative seek value -1

----------
components: Library (Lib)
messages: 414536
nosy: progval
priority: normal
severity: normal
status: open
title: tarfile.TarFile.next() crashes on empty tar files
versions: Python 3.10, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46922>
_______________________________________


More information about the New-bugs-announce mailing list