[Fontconfig] robustness of the mmap cache branch

Matthias Clasen mclasen at redhat.com
Thu Sep 8 01:08:22 EST 2005


I think FcGlobalCacheLoad() needs some robustness love. Just
copy any text file to ~/.fonts.cache-2 and watch FcGlobalCacheLoad()
go in an infinite loop:

    while (1) 
    {
	FcCacheReadString (cache->fd, name_buf, sizeof (name_buf));

	if (!strlen(name_buf))
	    break;

	d = malloc (sizeof (FcGlobalCacheDir));
	if (!d)
	    goto bail1;

	d->next = cache->dirs;
	cache->dirs = d;

	d->name = FcStrCopy (name_buf);
	d->ent = 0;
	d->offset = lseek (cache->fd, 0, SEEK_CUR);
	read (cache->fd, &d->metadata, sizeof (FcCache));
	lseek (cache->fd, d->metadata.count, SEEK_CUR);
    }

I have no concrete proposal for how to rework this, but at the very
least, the return values of read() and lseek() should be checked to
handle errors.


Regards, Matthias




More information about the Fontconfig mailing list