Skip to content

realpath has a race condition which might cause it to throw spurious exceptions #97566

Open
@bitonic

Description

@bitonic

Bug report

realpath tests if a file is a symlink using islink, which just returns False if the file does not exist. But then uses readlink a bit later to test the source of the link, which throws an exception if the file does not exists. If the file is a symlink and is deleted between islink and readlink, we get a spurious exception.

This reproduces the error using code copy-pasted from Python 3.9: https://gist.github.com/bitonic/e0977aaa674523a9ffe0e77a96cd6cc7 .

Your environment

  • CPython 3.9
  • ArchLinux x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10only security fixes3.11only security fixes3.12only security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions