Open giomf opened 3 months ago
Confirmed on the main branch. Here's an automated reproducer:
import os
import shutil
import tarfile
def main():
if os.path.exists("./test"):
# Remove from previous calls
shutil.rmtree("./test")
os.mkdir("./test")
os.symlink("/usr/bin/env", "./test/mylink")
with tarfile.open("./test.tar", "w") as tar:
tar.add("./test")
with tarfile.open('./test.tar') as tar_file:
member = tar_file.getmember('./test/mylink')
file_content = tar_file.extractfile(member)
if __name__ == '__main__':
main()
The same applies to hard links, fyi
Bug report
Bug description:
I have the following tar archive containing some files and a symlink to a file that is not part of the tar archive.
I want to extract the symlink. With the
getmember
method I receive a valid member of the tar archive. Using this member in theextractfile
however results in an error.As you can see
'test//usr/bin/env
can not be found. The path does not look like the symlink I try to extract but more like<symlink name>/<link target>
From the doc:
CPython versions tested on:
3.10, 3.12
Operating systems tested on:
Linux