]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149879: Fix test_tarfile on Cygwin (#149897)
authorVictor Stinner <vstinner@python.org>
Fri, 15 May 2026 20:49:37 +0000 (22:49 +0200)
committerGitHub <noreply@github.com>
Fri, 15 May 2026 20:49:37 +0000 (20:49 +0000)
On Cygwin, there is no root user (uid 0).

Fix test_realpath_limit_attack(): the test fails with ELOOP on
Cygwin.

Lib/test/test_tarfile.py

index 192c948edc605670f814447c42266c6ca72450f4..8e213a8f9992181703b16bc727ad6a35ff5fd738 100644 (file)
@@ -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
@@ -3985,6 +3989,9 @@ class TestExtractionFilters(unittest.TestCase):
                                  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)
@@ -4006,7 +4013,8 @@ class TestExtractionFilters(unittest.TestCase):
                         # 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):