GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pathlib.Path.resolve() mishandles symlink loops · Issue #109187 · python/cpython

pathlib.Path.resolve() mishandles symlink loops #109187

New issue
Copy link
New issue
Copy link
Closed
Closed
pathlib.Path.resolve() mishandles symlink loops#109187
Copy link
Labels
topic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@barneygale
barneygale
opened on Sep 9, 2023
Issue body actions

Bug report

Bug description:

Two closely-related issues in pathlib.Path.resolve():

First, resolve(strict=True) raises RuntimeError rather than OSError when a symlink loop is encountered. This is done only for backwards compatibility, since #25264 made pathlib call os.path.realpath(). It should raise OSError(ELOOP)

Second, resolve(strict=False) suppresses every kind of OS error except symlink loop errors. Again this is only for backwards compatibility. It should suppress exceptions about symlink loops.

Relevant code:

cpython/Lib/pathlib.py

Lines 1233 to 1252 in e21c89f

def check_eloop(e):
winerror = getattr(e, 'winerror', 0)
if e.errno == ELOOP or winerror == _WINERROR_CANT_RESOLVE_FILENAME:
raise RuntimeError("Symlink loop from %r" % e.filename)
try:
s = os.path.realpath(self, strict=strict)
except OSError as e:
check_eloop(e)
raise
p = self.with_segments(s)
# In non-strict mode, realpath() doesn't raise on symlink loops.
# Ensure we get an exception by calling stat()
if not strict:
try:
p.stat()
except OSError as e:
check_eloop(e)
return p

CPython versions tested on:

3.11, 3.12, CPython main branch

Operating systems tested on:

No response

Linked PRs

  • GH-109187: Improve symlink loop handling in pathlib.Path.resolve() #109192

Activity

  1. barneygale
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-pathlib
    on Sep 9, 2023
  2. barneygale
    added 2 commits that reference this issue on Sep 9, 2023

    pythonGH-109187: Improve symlink loop handling in `pathlib.Path.resol…

    245bcd2

    pythonGH-109187: Improve symlink loop handling in `pathlib.Path.resol…

    92dc2b3
  3. barneygale
    added a commit that references this issue on Sep 26, 2023

    GH-109187: Improve symlink loop handling in `pathlib.Path.resolve()` (G…

    ecd813f
  4. barneygale commented on Sep 26, 2023

    @barneygale
    barneygale
    on Sep 26, 2023
    ContributorAuthor
    More actions

    Addressed in 3.13 / ecd813f / #109192

  5. barneygale
    closed this as completedon Sep 26, 2023
  6. csm10495
    added a commit that references this issue on Sep 28, 2023

    pythonGH-109187: Improve symlink loop handling in `pathlib.Path.resol…

    7de1cc0
  7. Glyphack
    added a commit that references this issue on Sep 2, 2024

    pythonGH-109187: Improve symlink loop handling in `pathlib.Path.resol…

    ae001d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.