This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Samson Lee
Recipients Samson Lee
Date 2016-10-04.07:06:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The bug is os.fwalk() crashes with unhandled exception when there is an error
accessing symbolic link targets.

To reproduce the bug, create a symbolic link that targets a file that you do not
have permission to access:

    $ touch handsoff
    $ sudo chown root:root handsoff
    $ sudo chmod 700 handsoff
    $ ln -s handsoff blah

Now, os.fwalk() fails:

    >>> for root, dirs, files, fd in os.fwalk('.'):
    ...     print(root, dirs, files)
    Traceback (most recent call last):
      File "", line 3, in <module>
        for root, dirs, files, fd in os.fwalk('.'):
      File "/usr/lib64/python3.5/", line 520, in fwalk
        yield from _fwalk(topfd, top, topdown, onerror, follow_symlinks)
      File "/usr/lib64/python3.5/", line 537, in _fwalk
        if st.S_ISDIR(stat(name, dir_fd=topfd).st_mode):
    PermissionError: [Errno 13] Permission denied: 'blah'

The cause of the problem is in this part of

for name in names:
        # Here, we don't use AT_SYMLINK_NOFOLLOW to be consistent with
        # walk() which reports symlinks to directories as directories.
        # We do however check for symlinks before recursing into
        # a subdirectory.
        if st.S_ISDIR(stat(name, dir_fd=topfd).st_mode):
    except FileNotFoundError:
            # Add dangling symlinks, ignore disappeared files
            if st.S_ISLNK(stat(name, dir_fd=topfd, follow_symlinks=False)
        except FileNotFoundError:

To fix it, simply replace FileNotFoundError with more general OSError.

Date User Action Args
2016-10-04 07:06:56Samson Leesetrecipients: + Samson Lee
2016-10-04 07:06:56Samson Leesetmessageid: <>
2016-10-04 07:06:55Samson Leelinkissue28353 messages
2016-10-04 07:06:55Samson Leecreate