Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

os.path.realpath() produces unexpected results when run on a path created using the /proc/self/fd/ mechanism #99390

Closed as not planned
Labels
stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error
@sirosen

Description

@sirosen

Bug report

(editor's note: the description below indicates thatrealpath() is unaffected, but that's not correct - seecomment)

If a file descriptor is created in/proc/self/fd/ and then passed topathlib.Path, theresolve() method produces a result which is no longer a real and valid path to the file.
MRE, includingos.path.realpath for comparison:

importos,pathlibfd=os.memfd_create("myfd")print(pathlib.Path(f"/proc/self/fd/{fd}").resolve())# /memfd:myfd (deleted)print(os.path.realpath("/proc/self/fd/4"))# /proc/227671/fd/4

This can occur easily if another program uses the/proc/self/fd/ mechanism to pass temporary files to a python application.
For example, using ZSH on linux:

$ python -c 'import pathlib, sys; print(pathlib.Path(sys.argv[1]).resolve())' <(echo 'hi')/proc/234888/fd/pipe:[331484707]

I looked atpathlib.py and in 3.11 it looks like it's primarily relying onrealpath, so I'm not clear on where or how the discrepancy gets introduced. I'm sure I don't understand something aboutpathlib which explains.

Your environment

  • CPython versions tested on: 3.10, 3.11
  • Operating system and architecture: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp