Summary: | file open dialog crashes on paste/tree expanding | ||
---|---|---|---|
Product: | [Unmaintained] kio | Reporter: | Peter Oberndorfer <kumbayo84> |
Component: | general | Assignee: | David Faure <faure> |
Status: | RESOLVED FIXED | ||
Severity: | crash | CC: | adawit, antholinux, arekm, barnendu.goswami, frank78ac, karim.daumal |
Priority: | NOR | Keywords: | investigated |
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Unspecified | ||
Latest Commit: | Version Fixed In: | 4.6.4 | |
Sentry Crash Report: | |||
Attachments: |
Add some debug output to KDirOperator::Private::_k_slotExpandToUrl(...)
Patch (including unit test) |
Description
Peter Oberndorfer
2009-03-13 18:56:12 UTC
*** Bug 194666 has been marked as a duplicate of this bug. *** I can reproduce the crash in current trunk. Can reproduce on 4.5.4 (also in different form - https://bugs.kde.org/show_bug.cgi?id=260577) *** Bug 262181 has been marked as a duplicate of this bug. *** I cannot reproduce this crash though the steps to reproduce the problem seem to be missing a step. What exactly am I pasting into the "Name" box. It does not say to "Copy" something anywhere in the steps previous to that statement. Anyhow, some clarification would be nice or even better if anyone runs into this problem with the recent versions of KDE (v4.6 and up) ? Can anyone want to confirm this crash in the current trunk or KDE 4.7 beta 1 ? I personally cannot, but then again I did not clearly understand the instructions on how to reproduce... I can still reproduce the crash in today's master. I'll try to make the instructions a bit more detailed: 1. $ mkdir crash_test 2. $ touch crash_test/crash.txt 3. $ kwrite 4. File->Open (File open dialog starts in the current directory) 5. In the 'Name' line edit, enter '/', see the combo box open, and press backspace 6. Switch to the browser window showing this bug report 7. Mark the text 'crash_test/crash.txt' with the mouse 8. Go back to KWrite's file open dialog 9. Middle-click the 'Name' line edit to paste the text -> Crash (In reply to comment #7) > I can still reproduce the crash in today's master. I'll try to make the > instructions a bit more detailed: > > 1. $ mkdir crash_test > 2. $ touch crash_test/crash.txt > 3. $ kwrite > 4. File->Open (File open dialog starts in the current directory) > 5. In the 'Name' line edit, enter '/', see the combo box open, > and press backspace > 6. Switch to the browser window showing this bug report > 7. Mark the text 'crash_test/crash.txt' with the mouse > 8. Go back to KWrite's file open dialog > 9. Middle-click the 'Name' line edit to paste the text -> Crash Tried that multiple times and it does not crash here with today's master. Created attachment 60410 [details]
Add some debug output to KDirOperator::Private::_k_slotExpandToUrl(...)
The output I get just before the crash with this patch applied is:
kwrite(24307) KDirOperator::Private::_k_slotExpandToUrl: item: [KFileItem for KUrl("file:///home/kde-devel/tmp/crash_test/crash.txt") ]
kwrite(24307) KDirOperator::Private::_k_slotExpandToUrl: itemsToBeSetAsCurrent: (KUrl("file:///") , KUrl("file:///home/kde-devel/tmp/crash_test/crash.txt") , KUrl("file:///home/kde-devel/tmp/crash_test") )
kwrite(24307) KDirOperator::Private::_k_slotExpandToUrl: url: KUrl("file:///")
kwrite(24307) KDirOperator::Private::_k_slotExpandToUrl: _item: [null KFileItem]
The URL "file:///" had been appended to itemsToBeSetAsCurrent by KDirOperator::setCurrentItems(const QStringList& urls), but it cannot be found by the dir lister because it is not a subfolder of the folder which is shown in the dialog. This is why _item is a null KFileItem, and checking if it's a directory results in a crash.
Adding a null check for the file item fixes the crash for me (see below). But I'm not sure if this is the best way - the KFileItem API docs don't mention that calling isDir() for a null KFileItem crashes the app. So one could also move the null check to KFileItem::isDir() (and other similar methods), or the API docs should explicitly mention the crash risk. @David: Do you have an idea about this issue? --- a/kfile/kdiroperator.cpp +++ b/kfile/kdiroperator.cpp @@ -2526,7 +2526,7 @@ void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index) const KUrl url = *it; if (url.isParentOf(item.url())) { const KFileItem _item = dirLister->findByUrl(url); - if (_item.isDir()) { + if (!_item.isNull() && _item.isDir()) { const QModelIndex _index = dirModel->indexForItem(_item); const QModelIndex _proxyIndex = proxyModel->mapFromSource(_index); treeView->expand(_proxyIndex); Created attachment 60412 [details]
Patch (including unit test)
I've added a unit test which might be useful no matter how the bug is fixed. I've verified that the test crashes with an unpatched KDirOperator and passes with the patch from my previous comment applied.
(In reply to comment #10) > So one could also move the null check to KFileItem::isDir() (and other similar methods), or the > API docs should explicitly mention the crash risk. Hm, when I investigated another bug 196695, I found out that null KFileItems are used for special purposes in various places, and just make isDir() return false for them could cause other problems in the long run. So the best idea I have so far is my patch from comment 10. Git commit 8b5c38c8d9fae85e002fae9f325277b5b200d44d by Frank Reininghaus. Committed on 28/05/2011 at 17:00. Pushed by freininghaus into branch 'master'. Fix crash in KDirOperator::Private::_k_slotExpandToUrl(...) When entering '/' in the 'Name' line of the file open dialog, pressing backspace and then pasting 'a/b', where a is a subfolder of the current folder and b a file in that folder, KDirOperator may crash because it accesses a null KFileItem. This commit fixes the crash. Unit test included. CCBUG: 187066 M +1 -1 kfile/kdiroperator.cpp M +22 -0 kfile/tests/kdiroperatortest.cpp http://commits.kde.org/kdelibs/8b5c38c8d9fae85e002fae9f325277b5b200d44d Git commit dd4ff99421fc0aa96d74bc616e64137c11862f20 by Frank Reininghaus. Committed on 28/05/2011 at 17:00. Pushed by freininghaus into branch 'KDE/4.6'. Fix crash in KDirOperator::Private::_k_slotExpandToUrl(...) When entering '/' in the 'Name' line of the file open dialog, pressing backspace and then pasting 'a/b', where a is a subfolder of the current folder and b a file in that folder, KDirOperator may crash because it accesses a null KFileItem. This commit fixes the crash. Unit test included. BUG: 187066 FIXED-IN: 4.6.4 (cherry picked from commit 8b5c38c8d9fae85e002fae9f325277b5b200d44d) M +1 -1 kfile/kdiroperator.cpp M +22 -0 kfile/tests/kdiroperatortest.cpp http://commits.kde.org/kdelibs/dd4ff99421fc0aa96d74bc616e64137c11862f20 *** Bug 260577 has been marked as a duplicate of this bug. *** *** Bug 275818 has been marked as a duplicate of this bug. *** |