Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid infinite loops with symlinks #2707

Closed
wants to merge 2 commits into from
Closed

Conversation

ssbarnea
Copy link

@ssbarnea ssbarnea commented Jun 23, 2021

Fixes: #332

Summary of changes

Closes

Pull Request Checklist

@ssbarnea ssbarnea marked this pull request as ready for review June 23, 2021 11:24
Comment on lines +250 to +265
# https://bugs.python.org/issue44497
dirs = set()
files = set()
for dirpath, dirnames, filenames in os.walk(path, followlinks=True):
st = os.stat(dirpath)
scandirs = []
for dirname in dirnames:
st = os.stat(os.path.join(dirpath, dirname))
dirkey = st.st_dev, st.st_ino
if dirkey not in dirs:
dirs.add(dirkey)
scandirs.append(dirname)
dirnames[:] = scandirs
for f in filenames:
files.add(os.path.join(dirpath, f))
return files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be submitted to https://github.com/pypa/distutils first.

Comment on lines +216 to +231
# https://bugs.python.org/issue44497
dirs = set()
files = set()
for dirpath, dirnames, filenames in os.walk(path, followlinks=True):
st = os.stat(dirpath)
scandirs = []
for dirname in dirnames:
st = os.stat(os.path.join(dirpath, dirname))
dirkey = st.st_dev, st.st_ino
if dirkey not in dirs:
dirs.add(dirkey)
scandirs.append(dirname)
dirnames[:] = scandirs
for f in filenames:
files.add(os.path.join(dirpath, f))
return files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a regression test for this change?

@ssbarnea
Copy link
Author

ssbarnea commented Jun 23, 2021

As upstream pypa/distutils#44 is a very new project with a single maintainer and not really tested workflows (see its lack of CI jobs), I think we should aim to fix this here fist as it fixing a 6 years old bug which I consider critical, infinite loops.

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
@jaraco
Copy link
Member

jaraco commented Jul 5, 2021

See #2714, where I'm integrating the changes based on the report/PR in distutils. If these changes are needed for Setuptools separately from distutils (i.e. while Setuptools still falls back to stdlib distutils), let's use the implementation from distutils.

@jaraco jaraco closed this Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

distutils.filelist.findall falls into infinite loop over a symlink to a parent directory
3 participants