python / cpython

The Python programming language
https://www.python.org
Other
62.38k stars 29.96k forks source link

tarfile._FileInFile.seekable is broken in stream mode #70627

Open 93a5e510-e92b-47e3-8b6d-41e11073ce6f opened 8 years ago

93a5e510-e92b-47e3-8b6d-41e11073ce6f commented 8 years ago
BPO 26440
Nosy @gustaebel, @mlouielu, @jarondl, @charmander
PRs
  • python/cpython#8553
  • 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: ```python assignee = None closed_at = None created_at = labels = ['type-bug', 'library'] title = 'tarfile._FileInFile.seekable is broken in stream mode' updated_at = user = 'https://bugs.python.org/BillLee' ``` bugs.python.org fields: ```python activity = actor = 'Tiger-222' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'Bill Lee' dependencies = [] files = [] hgrepos = [] issue_num = 26440 keywords = ['patch'] message_count = 4.0 messages = ['260866', '260867', '290777', '299577'] nosy_count = 5.0 nosy_names = ['lars.gustaebel', 'Bill Lee', 'louielu', 'jarondl', 'charmander'] pr_nums = ['8553'] priority = 'normal' resolution = None stage = 'patch review' status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue26440' versions = ['Python 3.5'] ```

    93a5e510-e92b-47e3-8b6d-41e11073ce6f commented 8 years ago

    Description \=========== With a file object, retrieved by the extractfile method of a TarFile object opened in stream mode, calling its seekable method will raise an AttributeError.

    How to Reproduce \================ cat > seekable.py \<\< EOF import sys import tarfile tar = tarfile.open(fileobj=sys.stdin.buffer, mode='r|') contentFile = tar.extractfile(tar.next()) print(contentFile.seekable()) EOF

    tar -cf test.tar seekable.py python seekable.py \< test.tar

    Traceback \=========

    Traceback (most recent call last):
      File "seekable.py", line 5, in <module>
        print(contentFile.seekable())
      File "/usr/local/lib/python3.5/tarfile.py", line 649, in seekable
        return self.fileobj.seekable()

    How to Fix \========== I think that adding a method seekable(), which always return False, to tarfile._Stream will works.

    93a5e510-e92b-47e3-8b6d-41e11073ce6f commented 8 years ago

    I posted an incomplete traceback by mistake. Here is the whole traceback.

    Traceback \=========

    Traceback (most recent call last):
      File "seekable.py", line 5, in <module>
        print(contentFile.seekable())
      File "/usr/local/lib/python3.5/tarfile.py", line 649, in seekable
        return self.fileobj.seekable()
    AttributeError: '_Stream' object has no attribute 'seekable'
    9da18a29-a07d-4828-a801-24cc911246de commented 7 years ago

    Actually, _Stream does provide seek method, should the seekable just return True?

    9ebd57ca-3afd-4f57-a549-6a1ad70de606 commented 7 years ago

    _Stream provides seek, but only positive seeking is allowed. Is that considered seekable? Also, maybe _Stream should inherit from io.BaseIO. WDYT?

    erikvanzijst commented 1 year ago

    What's the status of this? Is anyone working on this?

    For anyone else ending up here looking for a workaround (e.g. when feeding tar files to boto3):

    fileobj = tar.extractfile(entry)
    fileobj.seekable = lambda: False
    s3_client.upload_fileobj(fileobj, bucket, target_path)