[Fontconfig] Patch: fix endless loop problem

Mike FABIAN mfabian at suse.de
Fri Jan 27 10:35:00 PST 2006


(Once again without the broken ~/.fonts.cache-2 file attached
because the message size was too big)

If this broken ~/.fonts.cache file exists (and no cache files are in
/var/cache/fontconfig) fontconfig (e.g. fc-match) loops endlessly,
eating up all system resources.

mfabian at magellan:~$ fc-cat .fonts.cache-2 | grep printing
fc-cat: printing global cache contents for dir /usr/share/fonts/wine
fc-cat: printing global cache contents for dir /usr/share/fonts
fc-cat: printing global cache contents for dir /usr/share/fonts/bdf
fc-cat: printing global cache contents for dir tmp.xemacs-patches.200505:xemacs-patches.200505.SCORE〓
mfabian at magellan:~$ 

Don't ask me how that strange last "directory" which doesn't really
exist of course got into that cache file. That must be due to yet
another weird bug in fontconfig. I have a *file* (not a directory!)
with a similar name in the "News" folder in my home directory:

mfabian at magellan:~$ ls News/*xemacs-patches.200505*
News/nndoc+.tmp.xemacs-patches.200505:xemacs-patches.200505.SCORE
mfabian at magellan:~$ 

But fontconfig has no business in ~/News, it is not listed as a
font directory in any config file.

Anyway, when reading this broken cache file, fontconfig loops
endlessly because the return value of FcCacheReadString () is not
checked in fccache.c around line 242:

	FcCacheReadString (cache->fd, name_buf, sizeof (name_buf));
	if (!strlen(name_buf))
	    break;

The return value of FcCacheReadString () is zero because the end of
the cache file has been reached but "name_buf" still contains the
previous contents, therefore it never breaks (by the way, it might be
a good idea to check the return value of the read () a few lines later
as well).

I've tried to fix this (and also tried to check the return value
at the other places where FcCacheReadString () was called, just
to make sure).

Patch attached.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: endless-loop.patch
Type: text/x-patch
Size: 2633 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20060127/86889a8c/endless-loop.bin
-------------- next part --------------

-- 
Mike FABIAN   <mfabian at suse.de>   http://www.suse.de/~mfabian
睡眠不足はいい仕事の敵だ。


More information about the Fontconfig mailing list