Commit Graph

255 Commits

Author SHA1 Message Date
Akira TAGOH 92f093a4c4 Report more detailed logs instead of assertion.
Getting backtraces against this assertion isn't useful at all.
Fontconfig isn't capable to report who really have a reference
of caches though, this report may be better than assertion.
So we can try analysis tools then.
And report it only when running with FC_DEBUG=16.
2023-01-25 14:36:30 +09:00
Ben Wagner efc71a3c13 Free local FcCache lock on contention
If two threads attempt to create the FcCache lock in lock_cache at the
same time, both threads may create and initialize a local FcMutex. One
thread will atomically make cache_lock point to its FcMutex. The other
thread currently calls FcMutexFinish on the local lock, but does not
free it. Change this behavior to free the unused lock.

Found with test/test-pthread on an LeakSanitizer enabled build.
2021-09-06 03:20:31 +00:00
Akira TAGOH 57032f489b Fix a memory leak when trying to open a non-existing file
https://bugzilla.redhat.com/show_bug.cgi?id=1914716
2021-08-25 15:52:53 +09:00
Alex Richardson 012ffaac75 Add support for C11 stdatomic atomics
This fixes deprecation warnings when building for macOS >= 10.12 systems.
Additionally, using stdatomic.h (or the more modern __atomic_ builtins)
is required when targeting CHERI-enabled architectures such as
CHERI-RISC-V or Arm's Morello since the compiler rejects __sync_* atomic
for pointer types (they only work with integers).
2021-07-20 09:32:52 +01:00
Ben Wagner 447b9ccc7d Fix fc_atomic_ptr_get and use.
Before this change building with ThreadSanitizer and running
test/test-pthread generated a large number of threading issues. These
mostly stemmed from fc_atomic_ptr_get not doing an atomic load and using
"acquire load" instead of "load acquire". After making these changes it
was still necessary to use fc_atomic_ptr_get where it was needed.

This also documents the current memory barrier requirements for the
atomic primitives.
2020-11-02 05:05:24 +00:00
Akira TAGOH 3ae08a8601 Make more clearer the license terms
COPYING is missing non-expat license terms for some files and some files is also missing license terms. This is changes to makes it clearer and update.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/219
2020-09-03 06:25:30 +00:00
Akira TAGOH a53f79b4a2 Fix build issues regarding formatter for Win32
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/248
2020-08-06 13:02:00 +09:00
Tim-Philipp Müller 03aa12c75e Guard dirent.h includes
Might not be available on Windows.
2020-07-27 13:43:23 +00:00
Akira TAGOH 437f03299b Fix empty XDG_CACHE_HOME Behavior
Use the default $HOME/.cache one for empty XDG_CACHE_HOME.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/243
2020-07-14 19:48:11 +09:00
Tim-Philipp Müller 93e65a8541 Fix build on Windows some more 2020-07-01 20:04:13 +01:00
Mathieu Duponchelle 7b293e3292 Some build fixes to support compilation with MSVC on Windows 2020-07-01 20:00:42 +01:00
Akira TAGOH fdbd9d13b7 Fix cache conflicts on OSTree based system
mtime isn't reliable to detect updates of fonts on OSTree based system
since they reset mtime to 0 for system files.
Due to this, there are the situation likely to happen where mtime is
newer but content is older.

Fortunately, OSTree based system requires reboot to deploy changes. so
we can assume we won't see any changes on system fonts. so system caches
are always up-to-date. we can ignore meta data for system fonts in
user caches.
2020-05-12 21:06:10 +09:00
Akira TAGOH 6f6b397802 Fix assertion in FcCacheFini() again
The previous fix in fbc05949ef was wrong. reverting.

When reading older caches, FcDirCacheMapHelper() returns FcFalse and
it became the return value from FcDirCacheProcess() too, which is wrong.
Actually one of calls for FcDirCacheMapHelper() should be successfully
finished and closure should have a valid pointer for cache.

Due to this, the proper finalization process wasn't running against
cache in closure.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/227
2020-03-23 14:08:55 +09:00
Akira TAGOH fbc05949ef Fix assertion in FcFini()
Due to the unproper initialization of `latest_mtime', the duplicate caches
was still in fcCacheChains with no references. which means no one frees
them. thus, the memory leak was happened.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/227
2020-02-26 15:42:21 +09:00
Akira TAGOH aa8c8cfa9f Fix potential race condition in FcConfigSetCurrent and FcConfigReference 2019-11-06 14:21:34 +09:00
Akira TAGOH b5bcf61fe7 Use FcConfigReference/Destroy appropriately instead of FcConfigGetCurrent
This may improves to be MT-safe.

Reported at https://bugs.chromium.org/p/chromium/issues/detail?id=1004254
2019-11-01 14:44:47 +09:00
Akira TAGOH a45fc8a332 Fix a memory leak caused by the previous commit 2019-10-31 16:15:25 +09:00
Akira TAGOH c9862b6ea7 Read latest cache in paths
Right now fontconfig uses a cache found first in a path and
cachedirs are the order of the system-wide path and then the user path.
this is due to avoid writing caches into the user path when running as root.

However, changing caches by certain config only, e.g. using <match target="scan">
may not take effect by this behavior, because it may be stored into the user path.

Thus, needing to find the latest cache out from paths.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/182
2019-10-28 17:15:07 +09:00
Akira TAGOH 957625bafa Fix the fail on fc-cache
Fallback code to UUID-based cache name was broken.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/169
2019-07-23 10:53:16 +00:00
Akira TAGOH 66b0af41b8 Fix endianness on generating MD5 cache name 2019-06-10 10:57:05 +00:00
Akira TAGOH 76e899700b No need to remap for uuid based 2019-04-04 11:57:13 +00:00
Akira TAGOH 7f61838435 Fallback uuid-based name to read a cache if no MD5-based cache available 2019-04-04 10:59:47 +00:00
Akira TAGOH d1acc73f23 Oops, Terminate string 2019-04-03 12:02:09 +00:00
Akira TAGOH fc9f706ecb Add some debugging output 2019-04-03 12:02:09 +00:00
Akira TAGOH 2e8ce63514 Add salt attribute to dir and remap-dir elements
'salt' attribute affects a cache filename to generate different name from directory name.
This is useful when sharing caches with host on sandbox and/or give a filename differently:

    <dir salt="randomdata">/usr/share/fonts</dir>
    <remap-dir as-path="/usr/share/fonts" salt="salt for /usr/share/fonts on host">/run/host/fonts</remap-dir>

Applications can read caches as-is for fonts on /run/host/fonts where is mounted from host.
and write a cache for their own fonts on /usr/share/fonts with different name.
2019-04-03 12:02:09 +00:00
Akira TAGOH 500e77a01d Drop a line to include uuid.h 2019-04-03 12:02:09 +00:00
Keith Packard c4324f54ee Replace UUID file mechanism with per-directory 'map' attribute [v2]
The UUID files would be placed in each font directory to provide the
unique cache name, independent of path, for that directory. The UUID
files are undesireable for a couple of reasons:

 1) They must be placed in the font directories to be useful. This
    requires modifying the font directories themselves, introducing
    potential visible timestamp changes when running multiple
    applications, and makes the cache processing inconsistent between
    applications with permission to write to the font directories and
    applications without such permission.

 2) The UUID contents were generated randomly, which makes the font
    cache not reproducible across multiple runs.

One proposed fix for 2) is to make the UUID dependent on the font
directory path, but once we do that, we can simply use the font
directory path itself as the key as the original MD5-based font cache
naming mechanism did.

The goal of the UUID file mechanism was to fix startup time of
flatpaks; as the font path names inside the flatpak did not match the
font path names in the base system, the font cache would need to be
reconstructed the first time the flatpak was launched.

The new mechanism for doing this is to allow each '<dir>' element in
the configuration include a 'map' attribute. When looking for a cache
file for a particular directory, if the directory name starts with the
contents of the <dir> element, that portion of the name will be
replaced with the value of the 'map' attribute.

Outside of the flatpak, nothing need change -- fontconfig will build
cache files using real directory names.

Inside the flatpak, the custom fonts.conf file will now include
mappings such as this:

	<dir map="/usr/share/fonts">/run/host/fonts</dir>

When scanning the directory /run/host/fonts/ttf, fontconfig will
use the name /usr/share/fonts/ttf as the source for building the cache
file name.

The existing FC_FILE replacement code used for the UUID-based
implementation continues to correctly adapt font path names seen by
applications.

v2:
	Leave FcDirCacheCreateUUID stub around to avoid removing
	public API function.

	Document 'map' attribute of <dir> element in
	fontconfig-user.sgml

	Suggested-by: Akira TAGOH <akira@tagoh.org>

Signed-off-by: Keith Packard <keithp@keithp.com>
2019-04-03 12:02:09 +00:00
Akira TAGOH 97fa77d27f Reset errno to do error handling properly
This fixes the weird behavior when running with SOURCE_DATE_EPOCH=0:

Fontconfig: SOURCE_DATE_EPOCH: strtoull: No such file or directory: 0
2019-04-03 11:49:42 +00:00
Akira TAGOH 98099ffc9f Ifdef'ed unnecessary code for Win32
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/147
2019-03-22 07:47:33 +00:00
Robert Yang 586e35450e src/fccache.c: Fix define for HAVE_POSIX_FADVISE
Otherwise, there would be build errors in the following 2 cases:
* define HAVE_POSIX_FADVISE
Or:
* undef HAVE_POSIX_FADVISE

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
2019-01-25 03:48:26 +00:00
Akira TAGOH b047e29954 Fix a dereference of a null pointer
When exiting from for loop by not satisfying the condition of `(s = next[i])` at FcCacheRemoveUnlocked()
referring s->alloated will be invalid.
2018-11-30 10:42:26 +00:00
Akira TAGOH 5f5ec5676c Do not try updating mtime when unlink was failed 2018-10-05 02:32:09 +00:00
Akira TAGOH ff5b49be2b Do not update mtime when removing .uuid file
This avoids a situation triggers updating caches on a directory where .uuid file was removed.

Resolves: https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/107
2018-10-05 02:32:07 +00:00
Akira TAGOH 586ac3b6c0 Fix array access in a null pointer dereference
FcFontSetFont() accesses fs->fonts in that macro though, there was no error checks
if it is null or not.
As a result, there was a code path that it could be a null.
Even though this is unlikely to see in usual use, it might be intentionally created
in a cache.

So if fs->fonts is a null, we should consider a cache is invalid.
2018-07-19 07:09:39 +00:00
Akira TAGOH 51afd09d62 Fix unterminated string issue 2018-07-19 05:51:02 +00:00
Akira TAGOH 4b1276e240 Fix memory leak 2018-07-19 03:14:54 +00:00
Akira TAGOH e9d3177557 Fix the leak of file handle 2018-07-19 11:32:50 +09:00
Matthieu Herrb 5a46d572c0 FcCacheFindByStat(): fix checking of nanoseconds field. 2018-07-10 12:27:16 +09:00
Tom Anderson 6cc99d6a82 Fix heap use-after-free 2018-06-13 17:05:54 +09:00
Akira TAGOH f5dd8512bd Remove .uuid when no font files exists on a directory
https://bugs.freedesktop.org/show_bug.cgi?id=106632
2018-06-11 17:03:46 +09:00
Alexander Larsson 3ea70f9368 Cache: Remove alias_table
There is really no need for this anymore

https://bugs.freedesktop.org/show_bug.cgi?id=106618
2018-05-25 14:43:06 +09:00
Alexander Larsson a63b9c622e Add FcCacheAllocate() helper
This lets you allocate a chunk of memory that will be freed when the cache
is freed.

https://bugs.freedesktop.org/show_bug.cgi?id=106618
2018-05-25 14:42:05 +09:00
Chris Lamb f098adac54 Ensure cache checksums are deterministic
Whilst working on the Reproducible Builds[0] effort, we noticed that
fontconfig generates unreproducible cache files.

This is due to fc-cache uses the modification timestamps of each
directory in the "checksum" and "checksum_nano" members of the _FcCache
struct. This is so that it can identify which cache files are valid
and/or require regeneration.

This patch changes the behaviour of the checksum calculations to prefer
the value of the SOURCE_DATE_EPOCH[1] environment variable over the
directory's own mtime. This variable can then be exported by build
systems to ensure reproducible output.

If SOURCE_DATE_EPOCH is not set or is newer than the mtime of the
directory, the existing behaviour is unchanged.

This work was sponsored by Tails[2].

 [0] https://reproducible-builds.org/
 [1] https://reproducible-builds.org/specs/source-date-epoch/
 [2] https://tails.boum.org/
2018-05-16 16:06:46 +09:00
Akira TAGOH 0b85e77ede Bug 106459 - fc-cache doesn't use -y option for .uuid files
https://bugs.freedesktop.org/show_bug.cgi?id=106459
2018-05-13 16:21:58 +09:00
Akira TAGOH e83f8777d5 Disable uuid related code on Win32 2017-12-18 21:45:13 +09:00
Akira TAGOH 182186e53a Do not update mtime with creating .uuid 2017-12-18 21:26:29 +09:00
Akira TAGOH 8ab4d67995 Replace uuid in the table properly when -r 2017-12-18 20:05:14 +09:00
Akira TAGOH 6b82c70835 Fix memory leak 2017-11-20 17:37:22 +05:30
Akira TAGOH 8f88b1c47c abstract hash table functions 2017-11-20 17:37:22 +05:30
Akira TAGOH b01bf646f1 Destroy the alias and UUID tables when all of caches is unloaded
When a cache contains no fonts, it will be unloaded immediately.
Previously the certain alias and UUID entries will be purged at that time though,
this doesn't work when the targeted directory has sub-directories.
To avoid the unnecessary cache creation with the md5-based naming, try to keep them
as far as possible.
Although this way seems not perfectly working if the first directory to look up is like that
2017-11-20 17:37:22 +05:30