Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
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