Skip to content

Avoid symlink infinite loops (separate concerns + repro)#46

Merged
jaraco merged 7 commits intomainfrom
bpo-44497/symlink-infinite-recursion
Jul 4, 2021
Merged

Avoid symlink infinite loops (separate concerns + repro)#46
jaraco merged 7 commits intomainfrom
bpo-44497/symlink-infinite-recursion

Conversation

@jaraco
Copy link
Member

@jaraco jaraco commented Jul 4, 2021

  • Add test capturing failure. Ref Avoid symlink infinite loops #44.
  • Ensure that the result contains only the one file, not all the different symlink variants to the same file.
  • Wrap walk result to prevent infinite recursion. Fixes bpo-44497.

@jaraco
Copy link
Member Author

jaraco commented Jul 4, 2021

Tests are failing on Python 3.6 (maybe 3.7) on Windows only, probably because os.path.realpath didn't work for Symlinks until a later Python.

@jaraco
Copy link
Member Author

jaraco commented Jul 4, 2021

It does look like the os.stat().st_ino/.st_dev check as proposed in #44 would work on older Pythons on Windows.

PS C:\> cmd /c dir /a
 Volume in drive C has no label.
 Volume Serial Number is 84D3-DD29

 Directory of C:\

07/04/2021  08:55 AM    <SYMLINK>      bar.py [foo.py]
06/05/2021  09:28 PM    <DIR>          Boot
06/05/2021  09:06 PM           409,168 bootmgr
09/15/2018  12:09 AM                 1 BOOTNXT
09/06/2020  07:41 AM    <DIR>          code
05/06/2020  10:10 PM    <JUNCTION>     Documents and Settings [C:\Users]
07/04/2021  08:54 AM                 0 foo.py
05/06/2020  09:48 PM             5,510 License.txt
06/09/2021  06:03 PM    <DIR>          Program Files
06/08/2021  04:43 PM    <DIR>          Program Files (x86)
06/09/2021  06:04 PM    <DIR>          ProgramData
06/09/2021  06:04 PM    <DIR>          Python39
06/05/2021  09:31 PM    <DIR>          Users
06/02/2021  06:13 PM         1,466,720 vs_buildtools.exe
05/11/2021  10:01 PM    <DIR>          WcSandboxState
06/09/2021  06:04 PM    <DIR>          Windows
               6 File(s)      1,881,687 bytes
              10 Dir(s)  21,230,219,264 bytes free
PS C:\> python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information.
>>> import os 
>>> os.stat('foo.py') 
os.stat_result(st_mode=33206, st_ino=281474976711654, st_dev=2228477225, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1625414073, st_mtime=1625414073, st_ctime=1625414073)
>>> os.stat('bar.py') 
os.stat_result(st_mode=33206, st_ino=281474976711654, st_dev=2228477225, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1625414073, st_mtime=1625414073, st_ctime=1625414073)

@jaraco jaraco force-pushed the bpo-44497/symlink-infinite-recursion branch from b85a9b5 to d616ed7 Compare July 4, 2021 16:31
@jaraco jaraco merged commit e2627b7 into main Jul 4, 2021
@jaraco jaraco deleted the bpo-44497/symlink-infinite-recursion branch July 4, 2021 16:32
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.

1 participant