Skip to content

tarfile.TarFile.next() crashes on empty tar files #91078

Closed

Description

@progval
mannequin
BPO 46922
Nosy @ethanfurman

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 = None
closed_at = None
created_at = <Date 2022-03-04.16:43:29.909>
labels = ['library', '3.9', '3.10']
title = 'tarfile.TarFile.next() crashes on empty tar files'
updated_at = <Date 2022-03-04.18:05:20.357>
user = 'https://bugs.python.org/progval'

bugs.python.org fields:

activity = <Date 2022-03-04.18:05:20.357>
actor = 'ethan.furman'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2022-03-04.16:43:29.909>
creator = 'progval'
dependencies = []
files = []
hgrepos = []
issue_num = 46922
keywords = []
message_count = 1.0
messages = ['414536']
nosy_count = 2.0
nosy_names = ['progval', 'ethan.furman']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue46922'
versions = ['Python 3.9', 'Python 3.10']

Linked PRs

Activity

  1. progval commented on Mar 4, 2022

    progvalmannequin
    MannequinAuthor

    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
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Mar 4, 2022
  3. transferred this issue fromon Apr 10, 2022
  4. dignissimus commented on Apr 23, 2022

    @dignissimus
    Contributor

    It looks like raising ReadError instead might be better.

    Edit: After reading the documentation for the next function, merely returning None seems to be the best option here.

  5. added a commit that references this issue on Nov 26, 2022
  6. added 2 commits that reference this issue on Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of life3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directory

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions