Commit graph

8125 commits

Author SHA1 Message Date
Tim Serong
09643ee1ab Avoid assert when drawing arcs with NaN angles
I hit the problem with _cairo_arc_in_direction() failing the
angle_max >= angle_min assertion earlier this year when using
Thunderbird on openSUSE Tumbleweed.  Thunderbird would crash
when rendering some (but not all) HTML email due to this
assert.  For some reason, one of the angles passed in was
NaN.  Making _cairo_arc_in_direction() return immediately if
either angle is not finite fixed the problem for me, but I
don't know enough about the internals of Cairo to know if
this is, strictly speaking, the "right" fix.  Also, having
tested again today _without_ this change applied, I am now
no longer able to reproduce the problem :-/  I still have the
same version of Cairo installed (1.17.8), but various other
packages on that system have been updated in the meantime,
so maybe that's a factor.  Or maybe I'm just lucky and
haven't hit a "bad" HTML email this time...?

Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/352
Signed-off-by: Tim Serong <tserong@suse.com>
2023-09-19 18:26:39 +10:00
Uli Schlachter
06864022c8 Fix font options leak in cairo script surface
I added options->variations = strdup("slnt=0,wght=400,wdth=100"); to the
end of _cairo_font_options_init_default(). This makes all font option
objects own some memory that needs to be freed. Then I ran some random
test under valgrind and found memory leaks.

This commit makes the script surface finish the font options that it
contains. This fixes the following valgrind report:

 25 bytes in 1 blocks are definitely lost in loss record 8 of 21
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4ECBC99: strdup (strdup.c:42)
    by 0x4886B7F: _cairo_font_options_init_default (cairo-font-options.c:86)
    by 0x49768F4: _cairo_script_implicit_context_init (cairo-script-surface.c:3676)
    by 0x4976B22: _cairo_script_surface_create_internal (cairo-script-surface.c:3733)
    by 0x4976EA1: cairo_script_surface_create (cairo-script-surface.c:3962)
    by 0x1B0A97: _cairo_boilerplate_script_create_surface (cairo-boilerplate-script.c:63)
    by 0x129B7F: cairo_test_for_target (cairo-test.c:824)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 10:00:51 +02:00
Uli Schlachter
29087868cd Fix font options leak in _cairo_surface_copy_similar_properties()
I added options->variations = strdup("slnt=0,wght=400,wdth=100"); to the
end of _cairo_font_options_init_default(). This makes all font option
objects own some memory that needs to be freed. Then I ran some random
test under valgrind and found memory leaks.

_cairo_surface_copy_similar_properties() gets the font options of a
surface via cairo_surface_get_font_options(). This creates a copy of the
font variations that I added above. _cairo_surface_set_font_options()
then copies this again (it calls _cairo_font_options_init_copy). Thus,
the original copy is still owned by
_cairo_surface_copy_similar_properties() and needs to be freed.

This commit fixes four leaks in "valgrind --leak-check=full
./cairo-test-suite -f leaks-set-scaled-font". A random example is:

 25 bytes in 1 blocks are definitely lost in loss record 4 of 25
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4ECBC99: strdup (strdup.c:42)
    by 0x4886C0C: _cairo_font_options_init_copy (cairo-font-options.c:99)
    by 0x48F1DDE: cairo_surface_get_font_options (cairo-surface.c:1620)
    by 0x48F0691: _cairo_surface_copy_similar_properties (cairo-surface.c:454)
    by 0x48F087C: cairo_surface_create_similar (cairo-surface.c:528)
    by 0x1B168A: _cairo_boilerplate_pdf_create_surface (cairo-boilerplate-pdf.c:92)
    by 0x129B7F: cairo_test_for_target (cairo-test.c:824)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 09:51:51 +02:00
Uli Schlachter
4c1987b0f0 Fix font options leak in cairo-surface.c
When calling cairo_surface_get_font_options(), a font options instance
is allocated for the surface. Normally, this just initialised some
otherwise uninitialised fields in cairo_surface_t. Since commit
67eeed44, cairo_font_options_t can contain an extra allocation for a
custom palette. Since commit edf9497c3a, cairo_font_options_t can
contain an extra allocation for a string. Before these commit, font
options could just be dropped, but now they need to be freed.

This commit makes cairo_surface_destroy() finish the contained font
options if they were initialised.

I didn't manage to produce a self-contained test case for this leak. I
found it by just looking at the code. However, I found a way to force a
leak: By adding options->variations=strdtup("slnt=0,wght=400,wdth=100");
to the end of _cairo_font_options_init_default(), all font option
instances now cause a leak unless they are finished. With this extra
change, this commit fixes a memory leak that is simply caused by calling
cairo_surface_get_font_options().

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 09:45:04 +02:00
Uli Schlachter
7bf743a92f Fix font options leak in scaled font
A scaled font contains font options. Since commit 67eeed44, this can
contain an extra allocation for a custom palette. Since commit
edf9497c3a, this contains an extra allocation for a string. Before these
commit, font options could just be dropped, but now they need to be
freed.

This commit makes the relevant code for creating and finishing scaled
fonts also clean up the font options.

The test added in the previous commit also hits this bug (I only found
these leaks accidentially!). Running "valgrind --leak-check=full
./cairo-test-suite -f leaks-set-scaled-font" no longer reports the following
after this change:

 40 bytes in 1 blocks are definitely lost in loss record 1 of 11
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
    by 0x48DAFFB: _cairo_scaled_font_init_key (cairo-scaled-font.c:675)
    by 0x48DC077: cairo_scaled_font_create (cairo-scaled-font.c:1096)
    by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
    by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

 40 bytes in 1 blocks are definitely lost in loss record 2 of 11
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
    by 0x49337BB: _cairo_ft_font_face_scaled_font_create (cairo-ft-font.c:2073)
    by 0x48DC340: cairo_scaled_font_create (cairo-scaled-font.c:1176)
    by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
    by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

 40 bytes in 1 blocks are definitely lost in loss record 3 of 11
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
    by 0x48DB280: _cairo_scaled_font_init (cairo-scaled-font.c:742)
    by 0x4933804: _cairo_ft_font_face_scaled_font_create (cairo-ft-font.c:2076)
    by 0x48DC340: cairo_scaled_font_create (cairo-scaled-font.c:1176)
    by 0x15BF08: leaks_set_scaled_font (leaks.c:43)
    by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 09:32:10 +02:00
Uli Schlachter
9529d02f6a Fix font options leak in gstate
cairo_gstate_t contains a cairo_font_options_t. Since commit 67eeed44,
this can contain an extra allocation for a custom palette. Since commit
edf9497c3a, this contains an extra allocation for a string. Before these
commit, font options could just be dropped, but now they need to be
freed.

This commit makes _cairo_gstate_fini() finish the font options to free
the memory allocation.

The new test was run via "valgrind --leak-check=full ./cairo-test-suite
-f leaks-set-scaled-font". The following reported leak goes away thanks
to this commit:

 1,040 bytes in 26 blocks are definitely lost in loss record 6 of 12
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4886C62: _cairo_font_options_init_copy (cairo-font-options.c:105)
    by 0x488C029: _cairo_gstate_set_font_options (cairo-gstate.c:1757)
    by 0x48841D7: _cairo_default_context_set_scaled_font (cairo-default-context.c:1310)
    by 0x490809A: cairo_set_scaled_font (cairo.c:3318)
    by 0x15BF1F: leaks_set_scaled_font (leaks.c:45)
    by 0x129EF0: cairo_test_for_target (cairo-test.c:938)
    by 0x12B37F: _cairo_test_context_run_for_target (cairo-test.c:1545)
    by 0x12C385: _cairo_test_runner_draw (cairo-test-runner.c:258)
    by 0x12DEB5: main (cairo-test-runner.c:962)

Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/795
Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-09-17 09:22:29 +02:00
Bobby Rong
50c5f3cc76 Fix building with -Werror=format-security
../src/cairo-pdf-surface.c: In function '_cairo_pdf_surface_open_content_stream':
../src/cairo-pdf-surface.c:2537:45: error: format not a string literal and no format arguments [-Werror=format-security]
 2537 |                                             str);
      |                                             ^~~
cc1: some warnings being treated as errors
2023-09-02 00:46:45 +00:00
Emmanuele Bassi
335c713ed7 tee: Remove questionable terminology
The master/slave terms are both inappropriate and inaccurate: the tee
surface replicates the rendering commands from a primary surface to
other surfaces.

This change is a mechanical search-and-replace.
2023-08-17 17:28:56 +01:00
Emmanuele Bassi
31fc7233a4 build: Remove unused files
We do not use slim symbols, and all the symbols are hidden by default;
this means we don't need to test those things any more.
2023-08-16 16:33:04 +01:00
Emmanuele Bassi
ba4d5fbd5d Build with hidden symbols by default
We should default on every platform we care about to hidden symbols, to
avoid leaking private symbols.

On Windows this is the default state of affairs with the MSVC toolchain;
with GCC and GCC-compatible toolchains, we need to opt into this
behaviour. Luckily for us, Cairo already has an annotation for public
symbols, so we can easily tweak it to include the visibility attribute.

When building ancillary libraries as part of the Cairo compilation on
Windows, we use a pre-processor symbol to ensure that we keep the
dllexport annotation. This avoids including the cairoint.h header file.

Fixes: #582
2023-08-16 16:33:04 +01:00
Emmanuele Bassi
77c2820840 Drop "slim" symbols
The original "slim" symbol rewriting was added without any shred of a
set of performance evaluation, and mostly copy-pasted from a very early
version of pixman. Pixman itself never used them, and most C
libraries—like GLib and GTK—have dropped similar mechanisms over the
past 15 years, as linkers have improved considerably in the meantime.

Modern linkers provide functionality to avoid intra-library PLT jump
through flags like `-Bsymbolic-functions`; we should use that, instead,
and keep the code base more maintainable and debuggable.
2023-08-16 16:33:04 +01:00
Uli Schlachter
05ba8e9751 Fix FT color glyphs on big endian systems
Andreas Falkenhahn reported the issue below and indicated that the color
channels are swapped. This commit fixes the byte swap.

The problem is that be32_to_cpu() is a no-op on big endian systems.
However, we also have a bswap_32() function available that always works.

Testing done: None by me, but Andreas Falkenhahn reported that his patch
fixes colors on a PowerPC system.

Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/787
Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-07-30 11:15:49 +02:00
iasunsea
35da42b681 fix SEGV in cairo_type1_font functioons 2023-07-22 11:58:20 +08:00
iasunsea
9a2385d412 fix read memory access 2023-07-21 00:46:44 +08:00
Tim-Philipp Müller
48a4466631 Merge branch 'fix-pulling-ft2-and-fc' into 'master'
Don't pull in FreeType and Fontconfig on Windows and Darwin

See merge request cairo/cairo!495
2023-07-20 14:50:07 +00:00
Adrian Johnson
3f732bd3d9 Merge branch 'master' into 'master'
cairo truetype reverse cmap detected memory leaks

See merge request cairo/cairo!494
2023-07-18 21:53:09 +00:00
Alex
af83da70f5 Refix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=56152 according to recommendations 2023-07-18 12:04:59 +00:00
Sergey Bugaev
7fe4f00721 Apply 1 suggestion(s) to 1 file(s) 2023-07-17 15:28:32 +00:00
Sergey Bugaev
bcb7937545 Consistently spell "FreeType" with capital T
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-07-17 15:35:40 +03:00
iasunsea
e2e826b0b1 cairo truetype reverse cmap detected memory leaks 2023-07-14 23:01:14 +08:00
Alex
90e38be99d Fix warning 2023-07-10 19:01:32 +00:00
Alex
2ecbfbce46 Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=56152 memory read access because of incorrect size 2023-07-10 18:36:53 +00:00
Jeremy Bícha
5118007b06 meson-check-def: Exclude sections from symbol list seen on mips 2023-07-03 09:30:51 -04:00
Jeremy Bícha
67c0202674 meson-check-def: Exclude sections from symbol list seen on ARM 2023-07-03 09:30:48 -04:00
Adrian Johnson
afac8b0e7d Avoid undefined signed left shift
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1841190
2023-06-30 18:43:00 +09:30
Uli Schlachter
42555cb0a7 Merge branch 'tag_stack' into 'master'
Fix use-after-free in _cairo_tag_stack_pop

See merge request cairo/cairo!483
2023-06-29 15:11:17 +00:00
Jonathan Kew
4e0f76473f Fix use-after-free in _cairo_tag_stack_pop 2023-06-29 12:52:33 +00:00
Matthias Clasen
05c6bb4ce1 Fix rendering of COLRv0 fonts
This was found while debugging why The Twemoji Mozilla
font renders a white-on-while in pango.

We need to call _render_glyph_bitmap, since we want
FT_Render_Glyph to handle the COLRv0 layers for us.
2023-06-06 14:44:52 -04:00
Adrian Johnson
90fda58934 Fix PS crash with color font and CAIRO_COLOR_MODE_NO_COLOR 2023-06-05 22:04:46 +09:30
Luca Bacci
50225f55ba Remove stray #error in dw-extra.h 2023-05-31 12:28:56 +02:00
Adrian Johnson
46e538ddbb Use a spinlock to prevent race condition when initializing mutexes
Fixes #782
2023-05-27 19:01:47 +09:30
Adrian Johnson
10cc34f521 ft: don't use scaled_glyph->dev_private to store data
It is also used by the xlib surface.

Fixes #778
2023-05-13 18:53:16 +09:30
Adrian Johnson
b86f24634c Don't assume HAVE_FT_PALETTE_SELECT is defined when HAVE_FT_SVG_DOCUMENT is defined
Fixes #777
2023-04-30 17:26:36 +09:30
Adrian Johnson
de9452438e pdf: Don't use snprintf() to print floats
It is not locale independent.
2023-04-18 18:27:12 +09:30
Adrian Johnson
b53b48116e Make cairo_tag_begin/end work correctly in groups
Fixes #508
2023-04-18 18:27:12 +09:30
Adrian Johnson
e7ed40a71d cairo-list-inline.h: fixes and documentation
- Fix a bug in cairo_list_is_singular
- Rename cairo_list_swap() to cairo_list_move_list()
  to better describe what it is doing.
2023-04-16 20:17:09 +09:30
Adrian Johnson
16074af6a1 win32: InterlockedCompareExchange uses LONG
Fixes #776
2023-04-13 06:03:22 +09:30
Adrian Johnson
d4d027d353 Merge branch 'issue-643' into 'master'
Fix missing glyphs in ft-font

Closes #643

See merge request cairo/cairo!467
2023-03-07 19:22:04 +00:00
Adrian Johnson
2766d9feec ft: Use normal font size when detecting the format
The format may depend on the font size.

Fixes #643
2023-03-07 19:41:39 +10:30
Uli Schlachter
af5a25a7f1 Merge branch 'unused-function' into 'master'
Fix -Wunused-function warnings

See merge request cairo/cairo!449
2023-03-03 15:50:32 +00:00
Uli Schlachter
3b178e8586 Merge branch 'ofz46165' into 'master'
ofz#46165 avoid a divide by zero seen fuzzing libreoffice rendering

See merge request cairo/cairo!351
2023-03-03 15:46:03 +00:00
Adrian Johnson
1f9004b3d0 Merge branch 'issue-3-win32-font-scale' into 'master'
win32 font is very small if the lfHeight of HFONT is exactly -size

Closes #3

See merge request cairo/cairo!466
2023-03-02 21:31:33 +00:00
Emmanuele Bassi
79c6beee90 Merge branch 'drop-xml-surface' into 'master'
Remove XML surface

See merge request cairo/cairo!446
2023-03-02 19:22:44 +00:00
Fujii Hironori
aa0aca3c65 win32 font is very small if the lfHeight of HFONT is exactly -size
cairo_win32_font_face_create_for_hfont is reusing the HFONT object
passed by an argument if possible to create a scaled font. However,
the condition was wrong. It checked the font matrix scale factor is
`-lfHeight`. But it should be `-lfHeight * WIN32_FONT_LOGICAL_SCALE`.

Fixes cairo/cairo#3
2023-03-03 04:15:10 +09:00
Matt Turner
2cd4256652 Open-code bbtree_del to avoid free()ing a non-allocated object
As we do already in _cairo_recording_surface_finish. Otherwise, the
cleanup path of _cairo_recording_surface_create_bbtree() could call
free() on surface->bbtree which is not dynamically allocated.

Closes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/645
2023-03-01 13:07:49 -05:00
Fujii Hironori
1b62ef3e55 DWrite: region clipping didn't work on win32 surfaces
The following clipping text tests of win32/rgb24 target were visibly
failing because clipping didn't work.

* clip-text
* partial-clip-text-bottom
* partial-clip-text-left
* partial-clip-text-right
* partial-clip-text-top

_cairo_win32_gdi_compositor_glyphs sets the clip. However,
_cairo_dwrite_show_glyphs_on_surface unset it.

Fixes cairo/cairo#641
2023-03-01 13:55:20 +09:00
Fujii Hironori
c33383b10d DWrite: Support antialias and subpixel order font options
Create a new IDWriteRenderingParams object from the given font
options.
2023-02-27 11:55:30 +09:00
Fujii Hironori
950e3fb45d Change the workaround of MinGW dwrite_3.h problem
The DWRITE_COLOR_GLYPH_RUN1 struct definition of the old MinGW
dwrite_3.h was invalid. To work around the problem, dw-extra.h defined
the correct struct definition and all necessary API from dwrite_3.h.
This approach needed to redefine all necessary API.

This change added DWRITE_COLOR_GLYPH_RUN1_WORKAROUND struct and use it
for IDWriteColorGlyphRunEnumerator1::GetCurrentRun.
2023-02-27 11:55:30 +09:00
Adrian Johnson
6a5f2140d7 Merge branch 'issue-569-dwrite-inflate-glyph-bounds' into 'master'
DWrite: Inflate glyph bounds 1px vertically too

Closes #569

See merge request cairo/cairo!461
2023-02-20 22:07:16 +00:00
Adrian Johnson
7a8aa5eb97 Merge branch 'fix-doc-for-cairo_matrix_transform_distance' into 'master'
Fix cairo_matrix_transform_distance documentation

See merge request cairo/cairo!462
2023-02-20 08:27:55 +00:00