Bug 324986

Summary: kfontview crashes when given a fontconfig: URL
Product: [Applications] kfontview Reporter: Jonathan Marten <jjm>
Component: generalAssignee: Craig Drummond <craig>
Status: RESOLVED FIXED    
Severity: crash CC: cfeck
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In: 4.11.2

Description Jonathan Marten 2013-09-17 09:08:41 UTC
If kfontview is called with a fontconfig: URL, it crashes with an assert:

kfontview "fontconfig:Arial"
ASSERT: "uint(i) < uint(size())" in file /usr/kde4/include/QtCore/qstring.h, line 701

If it is called with a font file pathname, this does not happen.

Unfortunately the "Open in Font Viewer" action in the Font Management systemsettings module (kcmshell4 fontinst) calls it with a fontconfig URL in the form "fontconfig:Arial?style=5268480".  The crash therefore happens every time this action is used.

I have not been able to get a backtrace of the assert, but by adding kDebug()'s it happens in kdeworkspace/kcontrol/kfontinst/viewpart/FontViewPart.cpp within void CFontViewPart::previewStatus(bool st):

            else if(!FC::decode(url()).family.isEmpty())
                printable=!Misc::isHidden(FC::getFile(url()));

Here FC::getFile(url()) returns a null string (the correct result) and Misc::isHidden() asserts because it tries to access the character at index 0 of that null string.


Reproducible: Always

Steps to Reproduce:
1.  Run 'kcmshell4 fontinst'
2.  Right click over a font in the list, and choose "Open in Font Viewer"

Or:

1.  Run 'kfontview fontconfig:NAME' where NAME is the name of an installed font.

Actual Results:  
Crash (of kfontview, not of systemsettings)


Expected Results:  
No crash


Patch to fix:

--- a/kcontrol/kfontinst/lib/Misc.h
+++ b/kcontrol/kfontinst/lib/Misc.h
@@ -59,7 +59,7 @@ namespace Misc
     };
 
     extern KDE_EXPORT QString prettyUrl(const KUrl &url);
-    inline KDE_EXPORT bool    isHidden(const QString &f)    { return QChar('.')==f[0]; }
+    inline KDE_EXPORT bool    isHidden(const QString &f)    { return f.startsWith(QChar('.')); }
     inline KDE_EXPORT bool    isHidden(const KUrl &url)     { return isHidden(url.fileName()); }
     extern KDE_EXPORT bool    check(const QString &path, bool file, bool checkW=false);
     inline KDE_EXPORT bool    fExists(const QString &p)     { return check(p, true, false); }
Comment 1 Christoph Feck 2013-09-17 22:06:05 UTC
Patch looks trivial, can you commit it to 4.11 branch?
Comment 2 Jonathan Marten 2013-09-18 07:38:54 UTC
Git commit 70fce20035225b948d87698547f1cb9d31a1f891 by Jonathan Marten.
Committed on 17/09/2013 at 09:12.
Pushed by marten into branch 'KDE/4.11'.

kfontview: do not crash when given a fontconfig: URL

M  +1    -1    kcontrol/kfontinst/lib/Misc.h

http://commits.kde.org/kde-workspace/70fce20035225b948d87698547f1cb9d31a1f891
Comment 3 Jonathan Marten 2013-09-18 07:39:28 UTC
Git commit 81cf614cf1b6736bbd441e2b52ea44bb33a1d79d by Jonathan Marten.
Committed on 17/09/2013 at 09:12.
Pushed by marten into branch 'master'.

kfontview: do not crash when given a fontconfig: URL

M  +1    -1    kcontrol/kfontinst/lib/Misc.h

http://commits.kde.org/kde-workspace/81cf614cf1b6736bbd441e2b52ea44bb33a1d79d