Page 1 of 1

Infinite recursion while searching through a symbolic link

Posted: 2018-08-30, 17:32 UTC
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.

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-08-30, 18:04 UTC
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.

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-08-30, 18:35 UTC
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?

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-08-30, 19:01 UTC
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

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-08-30, 19:23 UTC
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.

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-08-30, 19:26 UTC
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

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-08-30, 19:34 UTC
by Alexxx
2MVV
I changed the target of these links to relative and get the same problem in TC.

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-08-31, 05:35 UTC
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.

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-08-31, 08:04 UTC
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.

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-09-02, 10:34 UTC
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".

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-09-02, 18:06 UTC
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;

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-09-03, 14:30 UTC
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.

Re: Infinite recursion while searching through a symbolic link

Posted: 2018-09-03, 18:57 UTC
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...

Re: Infinite recursion while searching through a symbolic link

Posted: 2019-02-27, 16:18 UTC
by ghisler(Author)
This should be fixed in Total Commander 9.22 release candidate 1, please test it!