Skip to content

Commit 5c92d7b

Browse files
committed
Allow for can_hardlink() being false even if hardlinking is possible
1 parent 4ec9fea commit 5c92d7b

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

Lib/test/test_tarfile.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,16 +3838,10 @@ def test_realpath_limit_attack(self):
38383838
if sys.platform == 'win32':
38393839
self.expect_exception((FileNotFoundError, FileExistsError))
38403840
elif self.raised_exception:
3841-
# This block should never enter. This is left for debugging why
3842-
# there was an unexpected exception.
3843-
# Most likely, the guess for number of components was wrong?
3844-
try:
3845-
raise self.raised_exception
3846-
except KeyError:
3847-
pass
3848-
except OSError as exc:
3849-
self.assertEqual(exc.errno, errno.ENAMETOOLONG)
3850-
elif os_helper.can_symlink() and os_helper.can_hardlink():
3841+
# Cannot symlink/hardlink: tarfile falls back to getmember()
3842+
self.expect_exception(KeyError)
3843+
# Otherwise, this block should never enter.
3844+
else:
38513845
self.expect_any_tree(component)
38523846
self.expect_file('flaglink', content='overwrite')
38533847
self.expect_file('../newfile', content='new')
@@ -3856,17 +3850,15 @@ def test_realpath_limit_attack(self):
38563850

38573851
for filter in 'tar', 'data':
38583852
with self.subTest(filter), self.check_context(arc.open(), filter=filter):
3859-
if os_helper.can_hardlink():
3860-
exc = self.expect_exception(OSError)
3853+
exc = self.expect_exception((OSError, KeyError))
3854+
if isinstance(exc, OSError):
38613855
if sys.platform == 'win32':
38623856
# 3: ERROR_PATH_NOT_FOUND
38633857
# 5: ERROR_ACCESS_DENIED
38643858
# 206: ERROR_FILENAME_EXCED_RANGE
38653859
self.assertIn(exc.winerror, (3, 5, 206))
38663860
else:
38673861
self.assertEqual(exc.errno, errno.ENAMETOOLONG)
3868-
else:
3869-
self.expect_exception(KeyError)
38703862

38713863
@symlink_test
38723864
def test_parent_symlink2(self):

0 commit comments

Comments
 (0)