From 8cb70113d81a3ac560698c0e4c81942e16b1ede0 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 May 2026 20:58:40 +0200 Subject: [PATCH 1/3] gh-149879: Fix test_tarfile on Cygwin On Cygwin, there is no root user (uid 0). --- Lib/test/test_tarfile.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 192c948edc6056..52a52d0fdde1b7 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -3205,7 +3205,11 @@ def root_is_uid_gid_0(): import pwd, grp except ImportError: return False - if pwd.getpwuid(0)[0] != 'root': + try: + if pwd.getpwuid(0)[0] != 'root': + return False + except KeyError: + # On Cygwin, there is no root user (uid 0) return False if grp.getgrgid(0)[0] != 'root': return False From 2e68342c7b9c4eb79dfa5a09337a84a66c15ac8a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 May 2026 21:08:18 +0200 Subject: [PATCH 2/3] Fix also test_realpath_limit_attack() Fix test_realpath_limit_attack(): the test fails with ELOOP on Cygwin. --- Lib/test/test_tarfile.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 52a52d0fdde1b7..4ff1618da26d15 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -3949,7 +3949,7 @@ def test_realpath_limit_attack(self): # path fits in PATH_MAX, but it overflows when the final symlink # is expanded steps = "abcdefghijklmnop" - if sys.platform == 'win32': + if sys.platform in ('win32', 'cygwin'): component = 'd' * 25 elif 'PC_PATH_MAX' in os.pathconf_names: max_path_len = os.pathconf(self.outerdir.parent, "PC_PATH_MAX") @@ -3989,6 +3989,9 @@ def test_realpath_limit_attack(self): check_flag=False)): if sys.platform == 'win32': self.expect_exception((FileNotFoundError, FileExistsError)) + elif sys.platform == 'cygwin': + exc = self.expect_exception(OSError) + self.assertEqual(exc.errno, errno.ELOOP) elif self.raised_exception: # Cannot symlink/hardlink: tarfile falls back to getmember() self.expect_exception(KeyError) @@ -4010,7 +4013,8 @@ def test_realpath_limit_attack(self): # 206: ERROR_FILENAME_EXCED_RANGE self.assertIn(exc.winerror, (3, 5, 206)) else: - self.assertEqual(exc.errno, errno.ENAMETOOLONG) + self.assertIn(exc.errno, + (errno.ENAMETOOLONG, errno.ELOOP)) @symlink_test def test_parent_symlink2(self): From 22b4e785e85891d84e5507b64d4b8478ddf44b3e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 15 May 2026 22:17:57 +0200 Subject: [PATCH 3/3] Revert useless change --- Lib/test/test_tarfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 4ff1618da26d15..8e213a8f999218 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -3949,7 +3949,7 @@ def test_realpath_limit_attack(self): # path fits in PATH_MAX, but it overflows when the final symlink # is expanded steps = "abcdefghijklmnop" - if sys.platform in ('win32', 'cygwin'): + if sys.platform == 'win32': component = 'd' * 25 elif 'PC_PATH_MAX' in os.pathconf_names: max_path_len = os.pathconf(self.outerdir.parent, "PC_PATH_MAX")