Web lists-archives.com

kdelibs4support/kfiledialog causes crashing

Hello all,

I found a bug in kdelibs4support/kio/kfiledialog but can't quite work out where to file it in the bugtracker so I'll describe it here.

In short, some functions do not check whether d->native is non-null before calling a method belonging to the file chooser widget d->w. However, d->w is only set if d->native is null, so if this is not the case then the application crashes. This issue manifested on a windows build of kf5/okular by the application crashing in KFileDialog::setMimeFilter. However, I see that there are another half-dozen or so functions that have the same problem.

In any case I made the following patch and confirmed that with it okular can open files without crashing:

--- a/src/kio/kfiledialog.cpp
+++ b/src/kio/kfiledialog.cpp
@@ -326,8 +326,6 @@ QString KFileDialog::currentFilter() const
 void KFileDialog::setMimeFilter(const QStringList &mimeTypes,
                                 const QString &defaultType)
-    d->w->setMimeFilter(mimeTypes, defaultType);
     if (d->native) {
         QString allExtensions;
         QStringList filters = mime2KdeFilter(mimeTypes, &allExtensions);
@@ -336,6 +334,8 @@ void KFileDialog::setMimeFilter(const QStringList &mimeTypes,
         d->native->filter = filters.join(QLatin1String("\n"));
+    else
+        d->w->setMimeFilter(mimeTypes, defaultType);

Presumably all the other functions that do not currently test d->native should be made to do so.