This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tarfile.TarFile.next() crashes on empty tar files
Type: Stage:
Components: Library (Lib) Versions: Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ethan.furman, progval
Priority: normal Keywords:

Created on 2022-03-04 16:43 by progval, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg414536 - (view) Author: progval (progval) Date: 2022-03-04 16:43
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
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 91078
2022-03-04 18:05:20ethan.furmansetnosy: + ethan.furman
2022-03-04 16:43:29progvalcreate