mirror of
https://github.com/python/cpython.git
synced 2025-12-01 15:24:51 +00:00
gh-57911: Sanitize symlink targets in tarfile on win32 (GH-138309)
This commit is contained in:
parent
e76464d161
commit
c1a9c23195
4 changed files with 71 additions and 42 deletions
|
|
@ -2718,7 +2718,13 @@ class TarFile(object):
|
|||
if os.path.lexists(targetpath):
|
||||
# Avoid FileExistsError on following os.symlink.
|
||||
os.unlink(targetpath)
|
||||
os.symlink(tarinfo.linkname, targetpath)
|
||||
link_target = tarinfo.linkname
|
||||
if os.name == "nt":
|
||||
# gh-57911: Posix-flavoured forward-slash path separators in
|
||||
# symlink targets aren't acknowledged by Windows, resulting
|
||||
# in corrupted links.
|
||||
link_target = link_target.replace("/", os.path.sep)
|
||||
os.symlink(link_target, targetpath)
|
||||
return
|
||||
else:
|
||||
if os.path.exists(tarinfo._link_target):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue