Commit Graph

1018 Commits

Author SHA1 Message Date
Akira TAGOH 665584a19b Validate cache more carefully
Reject caches when FcPattern isn't a constant.
This is usually unlikely to happen but reported.
I've decided to add more validation since this isn't reproducible
and easy to have a workaround rather than investigating 'why'.

https://bugs.freedesktop.org/show_bug.cgi?id=103237
2017-11-14 20:59:27 +09:00
Alexander Kanavin b5016e3018 src/fcxml.c: avoid double free() of filename
It's also freed after bail1, so no need to do it here.
2017-10-12 11:26:21 +09:00
Akira TAGOH 33c760ce2d Fix again to keep the same behavior to the return value of FcConfigParseAndLoad
https://bugs.freedesktop.org/show_bug.cgi?id=102141
2017-09-21 16:57:55 +09:00
Akira TAGOH 918ed92226 Revert "Keep the same behavior to the return value of FcConfigParseAndLoad"
This reverts commit dc56ff8040.
2017-09-21 16:57:42 +09:00
Behdad Esfahbod ef3252e027 Minor 2017-09-21 16:53:35 +09:00
Akira TAGOH ee609da358 Fix to work the debugging option on fc-validate 2017-08-22 20:30:34 +09:00
Akira TAGOH 5efa1137b4 Accept 4 digit script tag in FcLangNormalize(). 2017-08-22 17:58:22 +09:00
Akira TAGOH 651f122764 Do not ship fcobjshash.gperf in archive 2017-08-15 18:20:15 +09:00
Akira TAGOH dc56ff8040 Keep the same behavior to the return value of FcConfigParseAndLoad
reverting the behavior accidentally changed by 12b750

https://bugs.freedesktop.org/show_bug.cgi?id=102141
2017-08-13 16:18:46 +09:00
Behdad Esfahbod 41bc5eab84 Fix weight mapping
Ouch!
2017-08-08 15:34:57 -07:00
Behdad Esfahbod 8b29103196 Fix warning 2017-08-04 14:23:10 +01:00
Behdad Esfahbod 484cb300ea Fix sign-difference compare warning 2017-08-04 14:23:10 +01:00
Behdad Esfahbod 9bb36b42c9 Minor 2017-08-04 12:23:28 +01:00
Behdad Esfahbod 064440d597 Ignore 'und-' prefix for in FcLangCompare
See https://bugs.freedesktop.org/show_bug.cgi?id=94551#c54

For example, matching for :lang=und-zsye matches emoji font, but searching
for :lang=und-xyz wouldn't match an emoji font anymore.  Neither does :lang-und.
2017-08-03 11:17:35 +01:00
Akira TAGOH 1bb8e691bd Add und-zsye.orth to support emoji in lang 2017-08-02 15:18:53 +01:00
Behdad Esfahbod 241cc86932 Pass --pic to gperf 2017-07-31 15:56:06 +01:00
Akira TAGOH 5b6af242e1 Fix gcc warnings with enabling libxml2 2017-07-11 15:38:01 +09:00
Akira TAGOH 12b7501bad Add FcConfigParseAndLoadFromMemory() to load a configuration from memory.
https://bugs.freedesktop.org/show_bug.cgi?id=78452
2017-07-07 15:52:15 +09:00
Akira TAGOH ee2000494c Add FcPatternGetWithBinding() to obtain the binding type of the value in FcPattern.
https://bugs.freedesktop.org/show_bug.cgi?id=19375
2017-07-07 15:43:59 +09:00
Akira TAGOH 047b42fcca Fix distcheck error 2017-07-05 17:35:28 +09:00
Josselin Mouette e831f12a38 Treat C.UTF-8 and C.utf8 locales as built in the C library.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717423
https://bugs.freedesktop.org/show_bug.cgi?id=101605
2017-06-27 21:21:18 +09:00
Florent Rougon 60e1fe550a FcCharSetFreezeOrig(), FcCharSetFindFrozen(): use all buckets of freezer->orig_hash_table
As written at:

  https://lists.freedesktop.org/archives/fontconfig/2017-June/005929.html

I think FcCharSetFreezeOrig() and FcCharSetFindFrozen() should use the %
operator instead of & when computing the bucket index for
freezer->orig_hash_table, otherwise at most 8 buckets among the 67
available (FC_CHAR_SET_HASH_SIZE) are used.

Another way would be to change FC_CHAR_SET_HASH_SIZE to be of the form
2**n -1 (i.e., a power of two minus one). In such a case, the & and %
operators would be equivalent.
2017-06-12 17:03:37 +09:00
Florent Rougon b0a5b4b48e FcLangSetCompare(): fix bug when two charsets come from different "buckets"
In fcLangCountrySets, it may happen that two charsets for the same
language but different territories are found in different FcChar32
"buckets" (different "columns" on the same line). This is currently the
case for the following pairs:

  mn-cn  and mn-mn
  pap-an and pap-aw

The FcLangSetCompare() code so far used to return FcLangDifferentLang
instead of FcLangDifferentTerritory when comparing:

  an FcLangSet containing only mn-cn with one containing only mn-mn

or

  an FcLangSet containing only pap-an with one containing only pap-aw

This commit fixes this problem.
2017-06-12 13:36:22 +09:00
Florent Rougon 209619b1a6 Fix erroneous test on language id in FcLangSetPromote()
FcLangSetIndex() indicates "not found" with a non-negative return value.
Return value 0 doesn't imply "not found", it rather means "language
found at index 0 in fcLangCharSets".
2017-06-09 15:52:23 +09:00
Florent Rougon 4970c7e810 Fix an off-by-one error in FcLangSetIndex()
This commit fixes a bug that can be reproduced like this:
  - remove all languages starting with 'a' in fc-lang/Makefile.am (in
    ORTH's definition);
  - rebuild fontconfig with this change (-> new fc-lang/fclang.h);
  - create an FcLangSet 'ls1' that contains at least the first language
    from fcLangCharSets (i.e., the first *remaining* in lexicographic
    order); let's assume it is "ba" for the sake of this description;
  - create an FcLangSet 'ls2' that only contains the language "aa" (any
    language starting with 'a' should work as well);
  - check the return value of FcLangSetContains(ls1, ls2);

The expected return value is FcFalse, however it is FcTrue if you use
the code before this commit.

What happens is that FcLangSetIndex() returns 0, because this is the
index of the first slot after the not-found language "aa" in
fcLangCharSets (since we removed all languages starting with 'a').
However, this index happens to be non-negative, therefore
FcLangSetContainsLang() mistakenly infers that the language "aa" was
found in fcLangCharSets, and thus calls FcLangSetBitGet(ls1, 0), which
returns FcTrue since we've put the first remaining language "ba" in the
'ls1' language set.

The "return -low;" statement previously in FcLangSetIndex() was
inconsistent with the final return statement. "return -(low+1);" fixes
this inconsistency as well as the incorrect behavior described above.
2017-06-09 14:35:43 +09:00
Florent Rougon c37eeb8f1f FcCharSetHash(): use the 'numbers' values to compute the hash
Before this commit, FcCharSetHash() repeatedly used the address of the
'numbers' array of an FcCharSet to compute the FcCharSet hash, instead
of the value of each array element. This is not good for even spreading
of the FcCharSet objects among the various buckets of the hash table
(and should thus reduce performance). This bug appears to have been
mistakenly introduced in commit
cd2ec1a940 (June 2005).
2017-06-07 11:17:15 +09:00
Akira TAGOH 28139816d6 Fix the build failure when srcdir != builddir and have gperf 3.1 or later installed 2017-06-05 21:00:36 +09:00
Akira TAGOH 5c49354a78 Force regenerate fcobjshash.h when updating Makefile
To avoid a situation of mismatching the declaration of hash function
2017-06-03 19:02:53 +09:00
Masamichi Hosoda 79058f4e91 Bug 99360 - Fix cache file update on MinGW
On Windows, opened or locked files cannot be removed.
Since fontconfig locked an old cache file while updating the file,
fontconfig failed to replace the file with updated file on Windows.

This patch makes fontconfig does not lock the old cache file
while updating it on Windows.
2017-06-01 11:46:07 +09:00
Akira TAGOH abdb6d658e Fix the build issue on GNU/Hurd
PATH_MAX isn't defined on GNU/Hurd. according to the porting guidelines
(https://www.gnu.org/software/hurd/hurd/porting/guidelines.html)
allocate a memory dynamically instead of relying on the length of
a string with PATH_MAX.

https://bugs.freedesktop.org/show_bug.cgi?id=97512
2017-03-01 19:48:38 +09:00
Akira TAGOH 9878b306f6 Fix the build issue with gperf 3.1
To support the one of changes in gperf 3.1:
* The 'len' parameter of the hash function and of the lookup function is now
  of type 'size_t' instead of 'unsigned int'. This makes it safe to call these
  functions with strings of length > 4 GB, on 64-bit machines.
2017-02-23 21:39:10 +09:00
Khem Raj 1ab5258f7c Avoid conflicts with integer width macros from TS 18661-1:2014
glibc 2.25+ has now defined these macros in <limits.h>
https://sourceware.org/git/?p=glibc.git;a=commit;h=5b17fd0da62bf923cb61d1bb7b08cf2e1f1f9c1a

Create an alias for FC_CHAR_WIDTH for ABI compatibility

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2016-12-20 16:33:07 +09:00
Akira TAGOH 0e9b2a1527 Fix FcCacheOffsetsValid()
Validation fails when the FcValueList contains more than font->num.
this logic was wrong because font->num contains a number of the elements
in FcPatternElt but FcValue in FcValueList.

This corrects 7a4a5bd7.

Patch from Tobias Stoeckmann
2016-11-14 20:16:40 +09:00
Tobias Stoeckmann 7a4a5bd789 Properly validate offsets in cache files.
The cache files are insufficiently validated. Even though the magic
number at the beginning of the file as well as time stamps are checked,
it is not verified if contained offsets are in legal ranges or are
even pointers.

The lack of validation allows an attacker to trigger arbitrary free()
calls, which in turn allows double free attacks and therefore arbitrary
code execution. Due to the conversion from offsets into pointers through
macros, this even allows to circumvent ASLR protections.

This attack vector allows privilege escalation when used with setuid
binaries like fbterm. A user can create ~/.fonts or any other
system-defined user-private font directory, run fc-cache and adjust
cache files in ~/.cache/fontconfig. The execution of setuid binaries will
scan these files and therefore are prone to attacks.

If it's not about code execution, an endless loop can be created by
letting linked lists become circular linked lists.

This patch verifies that:

- The file is not larger than the maximum addressable space, which
  basically only affects 32 bit systems. This allows out of boundary
  access into unallocated memory.
- Offsets are always positive or zero
- Offsets do not point outside file boundaries
- No pointers are allowed in cache files, every "pointer or offset"
  field must be an offset or NULL
- Iterating linked lists must not take longer than the amount of elements
  specified. A violation of this rule can break a possible endless loop.

If one or more of these points are violated, the cache is recreated.
This is current behaviour.

Even though this patch fixes many issues, the use of mmap() shall be
forbidden in setuid binaries. It is impossible to guarantee with these
checks that a malicious user does not change cache files after
verification. This should be handled in a different patch.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-05 14:35:05 +09:00
Akira TAGOH 99645ff9ee Bug 96676 - Check range of FcWeightFromOpenType argument
Fix a crash issue when FcWeightFromOpenType() gets a number more than it expects.
2016-07-08 14:18:35 +09:00
Akira TAGOH add5f7329f Remove unused code 2016-06-15 20:10:31 +09:00
Erik de Castro Lopo ea26c5e9f8 Fix a couple of minor memory leaks
These fixes are needed for the test suite to pass when compiled
with Address Sanitizer.
2016-05-30 10:30:10 +09:00
Akira TAGOH 7441dbec03 Bug 95481 - Build fails on Android due to broken lconv struct 2016-05-27 11:16:09 +09:00
Petr Filipsky d15c46d75e Fix memory leak in FcDirCacheLock 2016-05-23 11:09:22 +09:00
Akira TAGOH 9ab7633f2f Bug 95477 - FcAtomicLock fails when SELinux denies link() syscall with EACCES
This is an issue on Android M, which denies non-root users access to link().

Patch from Rodger Combs
2016-05-19 11:11:46 +09:00
Akira TAGOH d179cbc253 Revert "Workaround another race condition issue"
This reverts commit f44bfad235.
2016-04-06 14:39:15 +09:00
Behdad Esfahbod d05d083e9f [GX] Improve weight mapping
Align the 'wght' axis default value to OS/2 weight value and
adjust accordingly.  This makes both default=1.0 and default=400
models to work.
2016-03-08 17:20:55 -08:00
Behdad Esfahbod d709220d74 Improve OpenType to Fontconfig weight mapping 2016-03-08 17:20:28 -08:00
Behdad Esfahbod 27d61f1ddc [GX] Enumerate all named-instances in TrueType GX fonts 2016-03-08 13:39:05 -08:00
Behdad Esfahbod 00c8408c6a [GX] Support instance weight, width, and style name 2016-03-08 13:39:05 -08:00
Behdad Esfahbod 28f62d1bb8 Call FcFreeTypeQueryFace() from fcdir.c, instead of FcFreeTypeQuery()
Need for upcoming work.  No functional change expected.
2016-03-08 13:39:05 -08:00
Patrick Haller d570a841a2 Optimizations in FcStrSet
Applied optimizations:
- skip duplicate check in FcStrSetAppend for values originating from readdir()
- grow FcStrSet in 64-element bulks for local FcStrSets (FcConfig layout unaltered)

Starting gedit is measured to

                        Unoptimized     Optimized
user[s]                         0,806         0,579
sys[s]                          0,062         0,062
Total Instr Fetch Cost: 1.658.683.750   895.069.820
Cachegrind D Refs:        513.917.619   312.000.436
Cachegrind Dl Misses:       8.605.632     4.954.639
2016-01-12 10:42:40 +09:00
Akira TAGOH 1d87fab8b1 remomve unnecessary code 2015-11-18 14:44:17 +09:00
Akira TAGOH d162a4a83d Fix assertion on 32bit arch 2015-10-16 17:24:22 +09:00
Akira TAGOH bd96984e4b Use int64_t instead of long long 2015-10-15 15:51:50 +09:00