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
amatejamannequin opened this issue
Jun 2, 2021
· 4 comments
Labels
3.9only security fixes3.10only security fixes3.11bug and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
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=<Date2021-06-02.15:09:05.223>labels= ['type-bug', 'library', '3.9', '3.10', '3.11']
title='tarfile.is_tarfile() and tarfile.open() when used with file object may cause tarfile operations to fail'updated_at=<Date2022-02-09.16:19:26.161>user='https://github.com/amateja'
Since Python 3.9 tarfile.is_tarfile accepts not only paths but also files and file-like objects (bpo-29435).
Verification if a file or file-like object is a tar file modifies file object's current position.
Imagine a function listing names of all tar archive members but checking first if this is a valid tar archive. When its argument is a str or pathlib.Path this is quite straightforward. If the argument is a file of file-like object then current position must be reset or TarFile.getmembers() returns empty list.
This affects more use cases than just is_tarfile() and getmembers() results.
is_tarfile() calls open() which is the root cause of the issue. Calling open() 2+ times will also cause the same issue.
In addition to getmembers(), extracting the tar will also silently fail. (and possibly other operations).
I've suggested a different fix in the comment on the PR: #26488 (comment)
akulakov
changed the title
tarfile.is_tarfile() modifies file object's current position
tarfile.is_tarfile() and tarfile.open() when used with file object may cause tarfile operations to fail
Dec 9, 2021
akulakov
changed the title
tarfile.is_tarfile() modifies file object's current position
tarfile.is_tarfile() and tarfile.open() when used with file object may cause tarfile operations to fail
Dec 9, 2021
New changeset 128ab09 by Andrzej Mateja in branch 'main': bpo-44289: Keep argument file object's current position in tarfile.is_tarfile (GH-26488) 128ab09
3.9only security fixes3.10only security fixes3.11bug and security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: