Bug 292062 - KDirSelectDialog::selectDirectory usage results in an infinite loop
Summary: KDirSelectDialog::selectDirectory usage results in an infinite loop
Status: CONFIRMED
Alias: None
Product: kde-windows
Classification: Miscellaneous
Component: general (show other bugs)
Version: unspecified
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: KDE-Windows
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-20 20:19 UTC by Cristian Oneț
Modified: 2021-03-09 23:42 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to fix Windows specific code, you can see that the condition in the while loop is pretty weak and can lead to an infinite loop if the result of 'url.upUrl()' is 'url' (538 bytes, patch)
2012-01-20 20:19 UTC, Cristian Oneț
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Cristian Oneț 2012-01-20 20:19:06 UTC
Created attachment 68053 [details]
Patch to fix Windows specific code, you can see that the condition in the while loop is pretty weak and can lead to an infinite loop if the result of 'url.upUrl()' is 'url'

Version:           unspecified (using KDE 4.7.4) 
OS:                MS Windows

While investigating BUG 291850 I came across this issue. I've fixed BUG 291850 using a workaround (call KFileDialog::getExistingDirectoryUrl() instead which opens the native directory selection dialog).
The problem is that KDirSelectDialog::selectDirectory causes an infinite loop (see the attached patch for the reason).

Reproducible: Always

Steps to Reproduce:
Call KDirSelectDialog::selectDirectory() from an application.

Actual Results:  
Infinite loop plus a series of failed assertions.

Expected Results:  
Select a directory without problems.
Comment 1 Andre Heinecke 2012-01-23 08:34:41 UTC
Hi,
cool that you found this, what is the top level url KUrl url.upUrl() returns when you call it often enough? I would have expected it to be the same on Windows as on Linux (file:///) if that is not the case this bug might be a symptom of a bug in kurl.

I would think that "Call upUrl until you are on on the root" would be a strong enough break condition as long as it is clearly defined that infinite calls to upUrl on a local file url return file:///
Comment 2 Cristian Oneț 2012-01-23 08:41:03 UTC
If I remember correctly it was returning 'file:///C/' when the initial URL was a directory under C:/. But you can test this easily by calling KFileDialog::getExistingDirectoryUrl() and trying to navigate trough the directory structure. Once you click a directory to enter it this bug occurs.
Comment 3 Andre Heinecke 2012-01-23 09:12:37 UTC
I had this problem in Kontact before (when opening attachments) that some kde code assumes that file:/// points to the root directory but in fact according to RFC 1738

A file URL takes the form:
   file://<host>/<path>

So on Linux file:/// does not point to anything at all while on Windows file:///C/ points to the assumed root directory. Having different behavior there is bad.

The problem i see is that a fix to KURL to ultimately just return file:/// or file://// on linux and file:///C/ could lead to regressions.
Comment 4 Andre Heinecke 2012-01-23 16:24:03 UTC
This bug is fun.

According to the documentation: http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKUrl.html#a5a89a0a2d5af55d75e808cc029a24172

"The algorithm tries to go up on the right-most URL. If that is not possible it strips the right most URL. It continues stripping URLs."

So you would expect to end up with file:/// on Windows too (everything is stripped in the end)

But in the implementation:
http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/kurl_8cpp_source.html#l01475
it basically does cd ..
(So you would expect to end up with file://// on Linux and file:///C/ on Windows)

I would say the correct fix here would be to end up with file:/// on windows and linux because ultimately when you go upDir you want to end up on something like a drive overview and not on the current drive. Which would also be according to the documentation that it strips the rightmost url until no more url is left.
Comment 5 Justin Zobel 2021-03-09 23:42:38 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 5 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.