Skip to content

🐛 fix(discovery): don't hang on FIFO version files - #292

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/version-file-nonblocking-open
Nov 30, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/version-file-nonblocking-open

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Discovery reads .python-version files in the current folder and its parents, as pyenv does. Another user who can write a parent folder such as /tmp could swap that file for a named pipe between discovery's check and its read, and make discovery and the calling tool hang. 🔒 Version files are now opened without waiting, and anything that is not a regular file is skipped. This addresses draft advisory ANT-2026-2XCH1H5T.

lease.py opens the file and holds a write lease on it (fcntl(2) F_SETLEASE), as a backup or sync tool might:

$ mkdir -p pyenv/shims pyenv/versions/3.13/bin project
$ touch pyenv/shims/python3.13 && chmod +x pyenv/shims/python3.13
$ ln -s "$(uv python find 3.13)" pyenv/versions/3.13/bin/python3.13
$ echo 3.13 > pyenv/version && echo 3.13 > project/.python-version
$ cd project && python3 ../lease.py .python-version &
$ sleep 1
$ cd project && time PYENV_ROOT=$(dirname "$PWD")/pyenv PATH=$(dirname "$PWD")/pyenv/shims python -c 'from python_discovery import get_interpreter; print(get_interpreter("3.13").executable)'

Before:

/home/me/demo/pyenv/versions/3.13/bin/python3.13
real	0m45.404s

After:

/home/me/demo/pyenv/versions/3.13/bin/python3.13
real	0m0.490s

The disk cache already opens its entries this way (open(2) O_NONBLOCK); version files now follow it and check the opened file with S_ISREG before reading.

Regular and symlinked version files are read as before. Windows is unchanged. A file system that blocks while opening, such as an unresponsive network mount, is not covered.

Reported by oss-scanner: ANT-2026-2XCH1H5T.

Shim resolution checks that a .python-version path is a file, then opens it
by name. Another local user who can write to a shared parent directory can
swap in a FIFO between those two calls, and open() then waits for a writer
with no timeout to bound the wait, hanging discovery.

Open version files with O_NONBLOCK and check the descriptor that is read,
skipping anything that is not a regular file. O_NOFOLLOW is not used, so
symlinked version files keep working.

Reported by oss-scanner as ANT-2026-2XCH1H5T.
@gaborbernat gaborbernat added bug Something isn't working security Security fixes and advisories labels Nov 29, 2026
@gaborbernat
gaborbernat merged commit 9a717bd into tox-dev:main Nov 30, 2026
26 checks passed
@gaborbernat
gaborbernat deleted the fix/version-file-nonblocking-open branch November 30, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security Security fixes and advisories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant