[issue44495] wrong FNAME in tarfile if tgz extension is used

2021-11-01 Thread Rob Nelson


Rob Nelson  added the comment:

The code referenced in the previous comment only hits for tarfiles built from 
Streams. 

The same (incorrect) code exists in the gzip.py library as well, and hits the 
more common usecase of building a tar.gz from a set of files on disk.

def _write_gzip_header(self, compresslevel):
self.fileobj.write(b'\037\213') # magic header
self.fileobj.write(b'\010') # compression method
try:
# RFC 1952 requires the FNAME field to be Latin-1. Do not
# include filenames that cannot be represented that way.
fname = os.path.basename(self.name)
if not isinstance(fname, bytes):
fname = fname.encode('latin-1')
if fname.endswith(b'.gz'):
fname = fname[:-3]

This effects decompressing the file with 7zip, who respects the FNAME value, 
and thus attempts to create a new file with the same name as the file its 
currently decompressing. Or if you extract to another directory, it creates a 
tar file that is named "foo.tgz", which is confusing to users who are expecting 
a tar.

You can very easily reproduce this:

import tarfile
f = tarfile.open("test.tgz", mode="w:gz")
f.close()

and then "extract" the file with 7zip

--
nosy: +veaviticus

___
Python tracker 
<https://bugs.python.org/issue44495>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38523] ignore_dangling_symlinks in shutil.copytree does not apply recursively

2019-10-18 Thread Rob nelson


New submission from Rob nelson :

The ignore_dangling_symlinks attribute in shutil.copytree is not passed down 
recursively, resulting in dangling symlinks located anywhere other than the 
root of the source tree to raise an error.

The line causing the error for 3.9: 
https://github.com/python/cpython/blob/v3.8.0/Lib/shutil.py#L486

Trivial patches and an improved test case for:
3.7: 
https://github.com/veaviticus/cpython/commit/a662ae8a3f85380ec76ed3dfbc778aad8c5ac37a

3.8: 
https://github.com/veaviticus/cpython/commit/64f72c7196243bd3e2cf4136ebbb9f9ffe206750

3.9: 
https://github.com/veaviticus/cpython/commit/e55dd12e558443c350d241d87bf17dfc322dbfcf

--
components: Library (Lib)
messages: 354924
nosy: veaviticus
priority: normal
severity: normal
status: open
title: ignore_dangling_symlinks in shutil.copytree does not apply recursively
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8

___
Python tracker 
<https://bugs.python.org/issue38523>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com