Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tarfile.open does fails with UnicodeDecodeError if parent dir is unicode #52643

Closed
parthm mannequin opened this issue Apr 14, 2010 · 3 comments
Closed

tarfile.open does fails with UnicodeDecodeError if parent dir is unicode #52643

parthm mannequin opened this issue Apr 14, 2010 · 3 comments

Comments

@parthm
Copy link
Mannequin

parthm mannequin commented Apr 14, 2010

BPO 8396
Nosy @vstinner
Files
  • tarfilefail.py
  • 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 = <Date 2010-04-14.10:00:16.611>
    created_at = <Date 2010-04-14.09:50:02.647>
    labels = []
    title = 'tarfile.open does fails with UnicodeDecodeError if parent dir is unicode'
    updated_at = <Date 2010-04-14.10:00:16.609>
    user = 'https://bugs.python.org/parthm'

    bugs.python.org fields:

    activity = <Date 2010-04-14.10:00:16.609>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-04-14.10:00:16.611>
    closer = 'vstinner'
    components = []
    creation = <Date 2010-04-14.09:50:02.647>
    creator = 'parthm'
    dependencies = []
    files = ['16922']
    hgrepos = []
    issue_num = 8396
    keywords = []
    message_count = 3.0
    messages = ['103117', '103118', '103119']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'parthm']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue8396'
    versions = ['Python 2.6']

    @parthm
    Copy link
    Mannequin Author

    parthm mannequin commented Apr 14, 2010

    If any directory higher up in the hierarchy contains unicode chars, tarfile.open fails with UnicodeDecodeError. Attached script reproduces this error.

    [tmp]% python tarfilefail.py 
    Traceback (most recent call last):
      File "tarfilefail.py", line 9, in <module>
        tarfile.open(file_name, 'w')
      File "/usr/lib/python2.6/tarfile.py", line 1682, in open
        return cls.taropen(name, mode, fileobj, **kwargs)
      File "/usr/lib/python2.6/tarfile.py", line 1692, in taropen
        return cls(name, mode, fileobj, **kwargs)
      File "/usr/lib/python2.6/tarfile.py", line 1527, in __init__
        self.name = os.path.abspath(name) if name else None
      File "/usr/lib/python2.6/posixpath.py", line 338, in abspath
        path = join(os.getcwd(), path)
      File "/usr/lib/python2.6/posixpath.py", line 70, in join
        path += '/' + b
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 17: ordinal not in range(128)
    [tmp]%

    @vstinner
    Copy link
    Member

    It looks like tarfile doesn't support unicode filenames. You should try to encode your input filename to the file system default encoding (sys.getfilesystemencoding()), or avoid using unicode for tar filenames.

    @vstinner
    Copy link
    Member

    I proposed a workaround, the real bug is that os.path.abspath() doesn't support unicode... And this bug was already fixed 7 weeks ago by r78247 (issue bpo-3426).
    http://svn.python.org/view/python/trunk/Lib/posixpath.py?r1=78247&r2=78246&pathrev=78247

    Python 2.6.5 and 2.7b1 are fixed. So please upgrade :-)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant