Infinite recursion while searching through a symbolic link

Please report only one bug per message!

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Alexxx
Junior Member
Junior Member
Posts: 5
Joined: 2018-08-30, 16:30 UTC

Infinite recursion while searching through a symbolic link

Post by *Alexxx »

Try the following example:
1. Create a directory C:\MyDir.
2. Create a directory symbolic link C:\MyDir\MyDirLink with a root-relative target \MyDir
3. Run the file search for any files inside this directory: *
And it will get to an infinite recursion. In the results window you will see the following:
c:\MyDir\MyDirLink\
c:\MyDir\MyDirLink\MyDirLink\
c:\MyDir\MyDirLink\MyDirLink\MyDirLink\
c:\MyDir\MyDirLink\MyDirLink\MyDirLink\MyDirLink\
c:\MyDir\MyDirLink\MyDirLink\MyDirLink\MyDirLink\MyDirLink\
c:\MyDir\MyDirLink\MyDirLink\MyDirLink\MyDirLink\MyDirLink\MyDirLink\
...and so on.

But if you create a symbolic link with an absolute target (i.e. C:\MyDir) then no recursion will occur.
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6482
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Infinite recursion while searching through a symbolic link

Post by *Horst.Epp »

You will find that no such problem exists in a default Windows installation.
Here the correct access rights and settings don't get TC into a recursion loop.
You can of course generate such useless links for yourself and many problems not only in TC may occur.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3447)
TC 11.03 x64 / x86
Everything 1.5.0.1372a (x64), Everything Toolbar 1.3.3, Listary Pro 6.3.0.73
QAP 11.6.3.2 x64
Alexxx
Junior Member
Junior Member
Posts: 5
Joined: 2018-08-30, 16:30 UTC

Re: Infinite recursion while searching through a symbolic link

Post by *Alexxx »

Horst.Epp wrote: 2018-08-30, 18:04 UTC You can of course generate such useless links for yourself and many problems not only in TC may occur.
It's not useless, it's just a simple example. In real situations we can have a much longer path like "C:\MyDir\A\B\C\MyDirLink". And the result will be the same.
If you never use links then sure, it seems useless for you. But you can go to the Users directory and see how often the recursion links are using there. The only difference is they have an absolute path target.
And I don't understand what do you mean about "default windows installation", and how can it help. Did you try my example?
User avatar
HolgerK
Power Member
Power Member
Posts: 5406
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Re: Infinite recursion while searching through a symbolic link

Post by *HolgerK »

2Alexxx
F1,4b wincmd.ini wrote:IgnoreLinks=0 Allows to ignore hard links (junctions, reparse points) to directories in various functions. Note: The function "Synchronize dirs" uses a separate option "SyncIgnoreJunctions".
Sum of:
1: copy/move/calculate occupied space
2: internal packers (zip, tar)
4: branch view
8: find files (except when using Everything), re-scan tree
16: ignore links even when they are selected in the current directory. Otherwise only links in selected subdirectories are ignored.
maybe you should set this to the sum of all (IgnoreLinks=31) if you create and use such recursive links.

Regards
Holger
Make our planet great again
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: Infinite recursion while searching through a symbolic link

Post by *MVV »

But you can go to the Users directory and see how often the recursion links are using there. The only difference is they have an absolute path target.
These links have also special access rights: no one can enumerate contents, but anyone can read link target, so it is possible to access files and folders by full path. So programs don't have problems with recursion, while it is still possible to access old folders with new locations.
Alexxx
Junior Member
Junior Member
Posts: 5
Joined: 2018-08-30, 16:30 UTC

Re: Infinite recursion while searching through a symbolic link

Post by *Alexxx »

2HolgerK
It doesn't look like a solution. I don't need to ignore links. I need to ignore recursive links only. And obviously there is a bug in TC. Because I told already that same recursive links with absolute target work fine. So we have just some internal bug of TC.
p.s. Windows Explorer works fine in both cases. And Far Manager works fine as well
Last edited by Alexxx on 2018-08-30, 20:05 UTC, edited 2 times in total.
Alexxx
Junior Member
Junior Member
Posts: 5
Joined: 2018-08-30, 16:30 UTC

Re: Infinite recursion while searching through a symbolic link

Post by *Alexxx »

2MVV
I changed the target of these links to relative and get the same problem in TC.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: Infinite recursion while searching through a symbolic link

Post by *MVV »

I have D:\MainDir folder, D:\MainDir\MainDir_link link (with target \MainDir), and I'm trying to search for * in D:\MainDir or in D:\MainDir\MainDir_link.
IgnoreLinks=8 saves me from recursion, but if I remove IgnoreLinks key from INI, recursion appears.
Alexxx
Junior Member
Junior Member
Posts: 5
Joined: 2018-08-30, 16:30 UTC

Re: Infinite recursion while searching through a symbolic link

Post by *Alexxx »

MVV wrote: 2018-08-31, 05:35 UTC IgnoreLinks=8 saves me from recursion
It saves you from processing links at all :) Try to make a non-recursive dir link and put some files inside. They will be ignored.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48079
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Infinite recursion while searching through a symbolic link

Post by *ghisler(Author) »

The problem happens when
1. The link can be followed
2. The link target can NOT be read
3. The link points to its parent directory or above

In this case, TC follows the link because it cannot check whether the link causes a recursion or not due to "2".
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: Infinite recursion while searching through a symbolic link

Post by *MVV »

Well, I think there is an easy way to detect if it is a dir that is already enumerated - 64-bit filesystem entry index. Every NTFS item has unique number within the volume, and you can compare these indexes of directories. You can use e.g. a set for checking for already processed folders.

In this example all 4 paths give the same index because they point to the same file system item.

Code: Select all

	const wchar_t* paths[4] = {
		L"X:\\MainDir",
		L"X:\\MainDir\\.",
		L"X:\\MainDirLink",
		L"X:\\MainDirLink\\."
	};

	BY_HANDLE_FILE_INFORMATION infos[4] = { 0 };

	for (int i = 0; i < 4; ++i) {
		HANDLE hf = CreateFile(paths[i], GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
		GetFileInformationByHandle(hf, infos + i);
		CloseHandle(hf);
	}

	infos[0].nFileIndexHigh;
	infos[0].nFileIndexLow;
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48079
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Infinite recursion while searching through a symbolic link

Post by *ghisler(Author) »

Thanks, I will check that. But my guess is that when you aren't allowed to read the link target, then this CreateFile call will fail too. But it's worth a try.
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: Infinite recursion while searching through a symbolic link

Post by *MVV »

I think that if you're allowed to follow the link and access files/folders behind that link, you should be allowed to open target directory too...
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48079
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Infinite recursion while searching through a symbolic link

Post by *ghisler(Author) »

This should be fixed in Total Commander 9.22 release candidate 1, please test it!
Author of Total Commander
https://www.ghisler.com
Post Reply