Repository navigation
gh-160506: Fix ntpath.realpath() for broken links via directory links - #160507
Merged
Merged
Conversation
… links Resolve the directory containing a broken relative symlink before joining the link target to it, so that '..' in the target is applied to the real directory. ANT-2026-27II3A20
gpshead
marked this pull request as ready for review
October 25, 2026 06:03
Member
Author
|
!buildbot windows |
|
🤖 New build scheduled with the buildbot fleet by @gpshead for commit 5dbdc22 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F160507%2Fmerge The command will test the builders whose names match following regular expression: The builders matched are:
|
|
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12, 3.13, 3.14, 3.15. |
|
GH-161026 is a backport of this pull request to the 3.15 branch. |
|
GH-161027 is a backport of this pull request to the 3.14 branch. |
|
GH-161028 is a backport of this pull request to the 3.13 branch. |
|
GH-161029 is a backport of this pull request to the 3.12 branch. |
|
GH-161030 is a backport of this pull request to the 3.11 branch. |
gpshead
added a commit
that referenced
this pull request
Oct 31, 2026
…y links (GH-160507) (#161026) gh-160506: Fix ntpath.realpath() for broken links via directory links (GH-160507) Resolve the directory containing a broken relative symlink before joining the link target to it, so that '..' in the target is applied to the real directory. ANT-2026-27II3A20 (cherry picked from commit 65665a4) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ntpath._readlink_deep(), the fallbackrealpath()uses for a link Windows cannot open, now resolves the directory that contains the link with_getfinalpathname()before joining a relative target to it, so..in the target goes up from the real directory. It keeps the textual join only if that directory cannot be resolved with one of the error codes the function already tolerates. Two expectations intest_realpath_broken_symlinkschange (broken2andbroken3now resolve toABSTFN\missing), because they asserted the unresolved join.I could not run this on Windows: the changed branch and the
test_ntpathtests are skipped on Linux, where I only exercised the code over stand-ins for thentfunctions. It needs the Windows CI run before review.test_parent_symlink3intest_tarfilepasses on Linux with and without the change; its Windows branch is the one that depends on it.Fixes #160506
ANT-2026-27II3A20
os.path.realpath()on Windows misresolves a broken symlink reached through a directory symlink #160506