You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tarfile.TarFile.next() crashes on empty tar files #91078
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2022-03-04.16:43:29.909>labels= ['library', '3.9', '3.10']
title='tarfile.TarFile.next() crashes on empty tar files'updated_at=<Date2022-03-04.18:05:20.357>user='https://bugs.python.org/progval'
I found two related bugs when calling tarfile.TarFile.next() on an empty tar file, both when trying to seek when it should not:
importioimporttarfile# Create a tarball with no member:fd=io.BytesIO()
withtarfile.open(fileobj=fd, mode="w") astf:
pass# read in stream mode:fd.seek(0)
withtarfile.open(fileobj=fd, mode="r|") astf:
print(tf.next()) # tarfile.StreamError: seeking backwards is not allowed# read in normal mode:fd.seek(0)
withtarfile.open(fileobj=fd, mode="r") astf:
print(tf.next()) # ValueError: negative seek value -1
Activity
progval commentedon Mar 4, 2022
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:
dignissimus commentedon Apr 23, 2022
It looks like raising
ReadErrorinstead might be better.Edit: After reading the documentation for the
nextfunction, merely returningNoneseems to be the best option here.Merge branch 'main' into pythongh-91078
gh-91078: Return None from TarFile.next when the tarfile is empty (GH…
pythongh-91078: Return None from TarFile.next when the tarfile is emp…
gh-91078: Return None from TarFile.next when the tarfile is empty (GH…