Commit 8d885c97 authored by Frank Reininghaus's avatar Frank Reininghaus
Browse files

Fix possible crash in KDirModel if the root item is deleted or moved

If the root item of the dir model is deleted, but it is not the first
item in the list that KDirModelPrivate::_k_slotDeleteItems(...) gets
from the dir lister, a crash may result because
KDirModelPrivate::removeFromNodeHash(...) calls isDir() for a null
KFileItem. This commit extends the protection agains this kind of crash
that has been introduced in c8939409 for
the first item to the rest of the list.
BUG: 196695
FIXED-IN: 4.6.4
(cherry picked from commit 83538b43)
parent aa705f2a
......@@ -489,6 +489,11 @@ void KDirModelPrivate::_k_slotDeleteItems(const KFileItemList& items)
kWarning(7008) << "No node found for item that was just removed:" << url;
continue;
}
if (!node->parent()) {
// The root node has been deleted, but it was not first in the list 'items'.
// see https://bugs.kde.org/show_bug.cgi?id=196695
return;
}
}
rowNumbers.setBit(node->rowNumber(), 1); // O(n)
removeFromNodeHash(node, url);
......
......@@ -1066,6 +1066,27 @@ void KDirModelTest::testSmb()
}
}
class MyDirLister : public KDirLister
{
public:
void emitItemsDeleted(const KFileItemList& items) { emit itemsDeleted(items); }
};
void KDirModelTest::testBug196695()
{
KFileItem rootItem(KUrl(m_tempDir->name()), QString(), KFileItem::Unknown);
KFileItem childItem(KUrl(QString(m_tempDir->name() + "toplevelfile_1")), QString(), KFileItem::Unknown);
KFileItemList list;
// Important: the root item must not be first in the list to trigger bug 196695
list << childItem << rootItem;
MyDirLister* dirLister = static_cast<MyDirLister*>(m_dirModel->dirLister());
dirLister->emitItemsDeleted(list);
fillModel(true);
}
void KDirModelTest::testDeleteFile()
{
fillModel(false);
......
......@@ -60,6 +60,7 @@ private Q_SLOTS:
void testRemoteUrlWithHost();
void testZipFile();
void testSmb();
void testBug196695();
// These tests must be done last
void testDeleteFile();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment