From b05605cc1c1fc62b337aa0b82dd34ee5f0fe0332 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Thu, 18 Jun 2026 21:19:38 +0200 Subject: [PATCH 1/2] gh-151669: Normalize symlink targets in tarfile.TarFile.gettarinfo() This applies a normalization complementary to the one added to tarfile.TarFile.extract() in gh-138309. --- Lib/tarfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index a293a0492472749..90e3443a98d50f1 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2227,7 +2227,7 @@ def gettarinfo(self, name=None, arcname=None, fileobj=None): type = FIFOTYPE elif stat.S_ISLNK(stmd): type = SYMTYPE - linkname = os.readlink(name) + linkname = os.readlink(name).replace(os.sep, "/") elif stat.S_ISCHR(stmd): type = CHRTYPE elif stat.S_ISBLK(stmd): From 52b2be0ff507b3ee5a7cd4846d62bdfe76eeb4d6 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 24 Jun 2026 23:34:30 +0200 Subject: [PATCH 2/2] Add NEWS and whatsnew entries --- Doc/whatsnew/3.15.rst | 3 +++ .../Library/2026-06-24-23-28-42.gh-issue-151669.tPUavQ.rst | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-06-24-23-28-42.gh-issue-151669.tPUavQ.rst diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index db6903da9f63444..c4a2be12289d1c1 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1541,6 +1541,9 @@ tarfile now replace slashes with backslashes in symlink targets on Windows to prevent creation of corrupted links. (Contributed by Christoph Walcher in :gh:`57911`.) +* :func:`~tarfile.TarFile.gettarinfo` now replaces backslashes with slashes in + symlink targets on Windows to conform to the tar format standard. (Contributed + by Daniele Nicolodi in :gh:`151669`.) threading diff --git a/Misc/NEWS.d/next/Library/2026-06-24-23-28-42.gh-issue-151669.tPUavQ.rst b/Misc/NEWS.d/next/Library/2026-06-24-23-28-42.gh-issue-151669.tPUavQ.rst new file mode 100644 index 000000000000000..d8e4850ba94e140 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-24-23-28-42.gh-issue-151669.tPUavQ.rst @@ -0,0 +1,3 @@ +On Windows, when populating tar archives from filesystem content, to +conform to the tar format standard, backslashes in symlink targets are +be replaced by slashes.