Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 466432 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/fcfreetype.c (-3 / +32 lines)
Lines 1104-1110 FcFreeTypeQueryFace (const FT_Face face, Link Here
1104
    char	    psname[256];
1104
    char	    psname[256];
1105
    const char	    *tmp;
1105
    const char	    *tmp;
1106
1106
1107
    FcChar8	    *hashstr;
1107
    FcChar8	    *hashstr = NULL;
1108
    char	    *fontdata = NULL;
1109
    FT_Error	    err;
1110
    FT_ULong	    len = 0, alen;
1108
1111
1109
    pat = FcPatternCreate ();
1112
    pat = FcPatternCreate ();
1110
    if (!pat)
1113
    if (!pat)
Lines 1662-1673 FcFreeTypeQueryFace (const FT_Face face, Link Here
1662
    if (!FcPatternAddBool (pat, FC_DECORATIVE, decorative))
1665
    if (!FcPatternAddBool (pat, FC_DECORATIVE, decorative))
1663
	goto bail1;
1666
	goto bail1;
1664
1667
1665
    hashstr = FcHashGetSHA256DigestFromFile (file);
1668
    err = FT_Load_Sfnt_Table (face, 0, 0, NULL, &len);
1669
    if (err == FT_Err_Ok)
1670
    {
1671
	alen = (len + 63) & ~63;
1672
	fontdata = malloc (alen);
1673
	if (!fontdata)
1674
	    goto bail1;
1675
	err = FT_Load_Sfnt_Table (face, 0, 0, (FT_Byte *)fontdata, &len);
1676
	if (err != FT_Err_Ok)
1677
	    goto bail1;
1678
	memset (&fontdata[len], 0, alen - len);
1679
	hashstr = FcHashGetSHA256DigestFromMemory (fontdata, len);
1680
    }
1681
    else if (err == FT_Err_Invalid_Face_Handle)
1682
    {
1683
	/* font may not support SFNT. falling back to
1684
	 * read the font data from file directly
1685
	 */
1686
	hashstr = FcHashGetSHA256DigestFromFile (file);
1687
    }
1688
    else
1689
    {
1690
	goto bail1;
1691
    }
1666
    if (!hashstr)
1692
    if (!hashstr)
1667
	goto bail1;
1693
	goto bail1;
1668
    if (!FcPatternAddString (pat, FC_HASH, hashstr))
1694
    if (!FcPatternAddString (pat, FC_HASH, hashstr))
1669
	goto bail1;
1695
	goto bail1;
1670
    free (hashstr);
1671
1696
1672
    /*
1697
    /*
1673
     * Compute the unicode coverage for the font
1698
     * Compute the unicode coverage for the font
Lines 1756-1761 FcFreeTypeQueryFace (const FT_Face face, Link Here
1756
bail2:
1781
bail2:
1757
    FcCharSetDestroy (cs);
1782
    FcCharSetDestroy (cs);
1758
bail1:
1783
bail1:
1784
    if (hashstr)
1785
	free (hashstr);
1786
    if (fontdata)
1787
	free (fontdata);
1759
    FcPatternDestroy (pat);
1788
    FcPatternDestroy (pat);
1760
bail0:
1789
bail0:
1761
    return NULL;
1790
    return NULL;
(-)a/src/fchash.c (-1 / +56 lines)
Lines 220-226 FcHashGetSHA256DigestFromFile (const FcChar8 *filename) Link Here
220
220
221
    ret = FcHashInitSHA256Digest ();
221
    ret = FcHashInitSHA256Digest ();
222
    if (!ret)
222
    if (!ret)
223
	return NULL;
223
	goto bail0;
224
224
225
    while (!feof (fp))
225
    while (!feof (fp))
226
    {
226
    {
Lines 261-265 FcHashGetSHA256DigestFromFile (const FcChar8 *filename) Link Here
261
261
262
bail0:
262
bail0:
263
    fclose (fp);
263
    fclose (fp);
264
264
    return NULL;
265
    return NULL;
265
}
266
}
267
268
FcChar8 *
269
FcHashGetSHA256DigestFromMemory (const char *fontdata,
270
				 size_t      length)
271
{
272
    char ibuf[64];
273
    FcChar32 *ret;
274
    size_t i = 0;
275
276
    ret = FcHashInitSHA256Digest ();
277
    if (!ret)
278
	return NULL;
279
280
    while (i <= length)
281
    {
282
	if ((length - i) < 64)
283
	{
284
	    long v;
285
	    size_t n;
286
287
	    /* add a padding */
288
	    n = length - i;
289
	    if (n > 0)
290
		memcpy (ibuf, &fontdata[i], n);
291
	    memset (&ibuf[n], 0, 64 - n);
292
	    ibuf[n] = 0x80;
293
	    if ((64 - n) < 9)
294
	    {
295
		/* process a block once */
296
		FcHashComputeSHA256Digest (ret, ibuf);
297
		memset (ibuf, 0, 64);
298
	    }
299
	    /* set input size at the end */
300
	    v = length * 8;
301
	    ibuf[63 - 0] =  v        & 0xff;
302
	    ibuf[63 - 1] = (v >>  8) & 0xff;
303
	    ibuf[63 - 2] = (v >> 16) & 0xff;
304
	    ibuf[63 - 3] = (v >> 24) & 0xff;
305
	    ibuf[63 - 4] = (v >> 32) & 0xff;
306
	    ibuf[63 - 5] = (v >> 40) & 0xff;
307
	    ibuf[63 - 6] = (v >> 48) & 0xff;
308
	    ibuf[63 - 7] = (v >> 56) & 0xff;
309
	    FcHashComputeSHA256Digest (ret, ibuf);
310
	    break;
311
	}
312
	else
313
	{
314
	    FcHashComputeSHA256Digest (ret, &fontdata[i]);
315
	}
316
	i += 64;
317
    }
318
319
    return FcHashSHA256ToString (ret);
320
}
(-)a/src/fcint.h (+5 lines)
Lines 818-826 FcFontSetSerialize (FcSerialize *serialize, const FcFontSet * s); Link Here
818
FcPrivate FcChar8 *
818
FcPrivate FcChar8 *
819
FcHashGetSHA256Digest (const FcChar8 *input_strings,
819
FcHashGetSHA256Digest (const FcChar8 *input_strings,
820
		       size_t         len);
820
		       size_t         len);
821
821
FcPrivate FcChar8 *
822
FcPrivate FcChar8 *
822
FcHashGetSHA256DigestFromFile (const FcChar8 *filename);
823
FcHashGetSHA256DigestFromFile (const FcChar8 *filename);
823
824
825
FcPrivate FcChar8 *
826
FcHashGetSHA256DigestFromMemory (const char *fontdata,
827
				 size_t      length);
828
824
/* fcinit.c */
829
/* fcinit.c */
825
FcPrivate FcConfig *
830
FcPrivate FcConfig *
826
FcInitLoadOwnConfig (FcConfig *config);
831
FcInitLoadOwnConfig (FcConfig *config);

Return to bug 466432