python / cpython

The Python programming language
https://www.python.org
Other
63.79k stars 30.55k forks source link

glob.glob with ** does not always detect symlink loops #88041

Open c103b3da-8d2d-4263-a996-57e557bc5081 opened 3 years ago

c103b3da-8d2d-4263-a996-57e557bc5081 commented 3 years ago
BPO 43875

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['library', '3.9'] title = 'glob.glob with ** does not always detect symlink loops' updated_at = user = 'https://bugs.python.org/rrt' ``` bugs.python.org fields: ```python activity = actor = 'rrt' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'rrt' dependencies = [] files = [] hgrepos = [] issue_num = 43875 keywords = [] message_count = 1.0 messages = ['391253'] nosy_count = 1.0 nosy_names = ['rrt'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = None url = 'https://bugs.python.org/issue43875' versions = ['Python 3.9'] ```

c103b3da-8d2d-4263-a996-57e557bc5081 commented 3 years ago

Example session:

$ mkdir foo
$ cd foo
$ ln -s .. bar
$ ln -s .. baz
$ python3.9
Python 3.9.0+ (default, Oct 20 2020, 08:43:38) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from glob import glob
>>> glob('**/README', recursive=True)
[HANG]

Removing either of the symlinks fixes the hang.

calestyo commented 2 years ago

It seems to blow up already when using a **/* pattern on a directory containing a symlink to ..

calestyo commented 2 years ago

Sidenote: pathlib’s Path.glob()-function does not seem to suffer from that problem, however pathlib does not seem to be able to handle all possible pathnames (in POSIX pathnames allow any characters except NUL, while the module seems to handle only UTF8 strings), so may not be an alternative.

barneygale commented 8 months ago

Still reproducible in main as of 68b8ffff8c4b20d2f46b708b1a7906377ecc255f