Commit graph

8279 commits

Author SHA1 Message Date
Adrian Johnson
ded2092e20 Ensure outline font is used when CAIRO_COLOR_MODE_NO_COLOR is set 2023-01-17 22:57:15 +10:30
Adrian Johnson
745c3717aa Merge branch 'fix-shared-recording-surface' into 'master'
Fix shared use of recording surfaces

See merge request cairo/cairo!391
2023-01-16 08:59:32 +00:00
Adrian Johnson
6abc8076c9 Merge branch 'meson-and-doc-fixes' into 'master'
Meson and documentation fixes

See merge request cairo/cairo!406
2023-01-16 08:57:45 +00:00
Uli Schlachter
b23ecf6322 Merge branch 'test-png16-load' into 'master'
Add test for loading 16 bit PNG images

See merge request cairo/cairo!241
2023-01-15 19:54:04 +00:00
Adrian Johnson
7146358250 Fix shared use of recording surface with paginated targets
The problem is _cairo_recording_surface_replay_and_create_regions()
stores the cairo_recording_region_type_t in the same structure as the
recording commands. This does not work well when the recording surface
is used as source by multiple surfaces

Fix this by moving the cairo_recording_region_type_t into a separate
struct cairo_recording_regions_array_t. This struct is stored in a
list that allows multiple create regions results to be store in the
surface.

The new function _cairo_recording_surface_region_array_attach() is
used to create a new cairo_recording_regions_array_t, attach it to the
recording surface and return a unique region id.

The _cairo_recording_surface_replay_and_create_regions() and
_cairo_recording_surface_replay_region() functions use this region id
to identify the cairo_recording_regions_array_t.

To handle nested recording surfaces, when replaying a recording, the
region id is passed to the target as an extra parameter in the surface
pattern. The wrapper surface makes a temporary copy of the pattern to
ensure the snapshot pattern in the recording surface is not modified.

cairo_recording_regions_array_t has a reference count so the target
can hold on to the cairo_recording_regions_array_t after the paginated
surface has called _cairo_recording_surface_region_array_remove().
2023-01-15 19:29:28 +10:30
Adrian Johnson
d027f15075 Documentation fixes 2023-01-15 19:00:22 +10:30
Adrian Johnson
c80cd3a0c6 Merge branch 'defining-windows-version-macros-in-meson-build' into 'master'
Defining Windows version macros in meson.build

See merge request cairo/cairo!404
2023-01-12 21:33:19 +00:00
Fujii Hironori
8520ef5221 Defining Windows version macros in meson.build
WINVER and _WIN32_WINNT macros were defined in each source files and
headers that were including <windows.h>. However, because DirectWrite
requires new Windows API, some files included <windows.h> without the
version macros. This inconsistency sometimes caused troubles.

Define the version macros in meson.build.
2023-01-13 05:47:03 +09:00
Adrian Johnson
dc4a887e7f PS: Wrap embedded EPS in %%BeginDocument/%%EndDocument as required by EPS spec
Fixes #620
2023-01-12 07:32:44 +10:30
Adrian Johnson
1e0249ae0d Merge branch 'bug-606' into 'master'
sizeof(cairo_atomic_int_t) should be sizeof(int)

Closes #606

See merge request cairo/cairo!401
2023-01-11 21:02:00 +00:00
Manuel Stoeckl
39179681d4 Add array bounds check for xrender format lookup
Before this change, images with RGB30, RGB96F, and RGBA128F formats
would have been given garbage xrender formats; now such images
use the fallback path and are converted to formats with an xrender
equivalent.
2023-01-11 06:38:43 -05:00
Adrian Johnson
08194cef53 Merge branch 'bug-619' into 'master'
Remove the unbounded recording surface assertion

Closes #619

See merge request cairo/cairo!399
2023-01-11 07:53:11 +00:00
Adrian Johnson
ad04670971 Merge branch 'bug-566' into 'master'
DWrite: Don't call _controlfp_s with MCW_PC

Closes #566

See merge request cairo/cairo!400
2023-01-10 21:31:05 +00:00
Fujii Hironori
2135fd4a49 sizeof(cairo_atomic_int_t) should be sizeof(int)
`_cairo_status_set_error` was using `_cairo_atomic_int_cmpxchg` to set
a `cairo_status_t` variable by casting a `cairo_status_t*` to
`cairo_atomic_int_t*`. `cairo_atomic_int` has a generic implementation
which is using a mutex. In the implementation, `cairo_atomic_int_t`
was typedef-ed to `cairo_atomic_intptr_t`. In a typical 64bit system,
cairo_atomic_intptr_t is 64bit and cairo_status_t is 32bit,
_cairo_status_set_error didn't work as expected.

Define `cairo_atomic_int_t` as an alias of `int`.
Added an assertion in `_cairo_status_set_error` to ensure
that `*err` has the same size with `cairo_atomic_int_t`.

Fixes cairo/cairo#606
2023-01-11 06:11:28 +09:00
Fujii Hironori
a599720c88 DWrite: Don't call _controlfp_s with MCW_PC
GeometryRecorder class was calling _controlfp_s with MCW_PC to reset
the floating point precision to default. However, MCW_PC isn't
supported for ARM or x64 platforms. It reports an assertion failure
for them. And, Cairo isn't changing the MCW_PC setting. Removed the
calls. Also, removed `GetFixedX` and `GetFixedY` methods because they
called only `_cairo_fixed_from_double`.

Fixes cairo/cairo#566
2023-01-11 05:39:13 +09:00
Uli Schlachter
5ecfc2eb5d Merge branch 'bug-607' into 'master'
Don't leave a font face in an error state after a scaled font creation failure

Closes #607

See merge request cairo/cairo!402
2023-01-10 17:10:10 +00:00
Adrian Johnson
72cc5ae5fa Merge branch 'pr/Fix617' into 'master'
Fix wrong paginated surface size (issue #617)

Closes #617

See merge request cairo/cairo!395
2023-01-10 11:10:08 +00:00
Adrian Johnson
1cfea7d979 Merge branch 'colr-v1' into 'master'
COLRv1 glyph renderer

See merge request cairo/cairo!397
2023-01-10 11:09:11 +00:00
Fujii Hironori
5e73c107f5 Don't leave a font face in an error state after a scaled font creation failure
Scaled font creation may fail if the font size is very large on
win32. But, don't leave the font face in an error state in such
case.

Fixes cairo/cairo#607
2023-01-10 16:01:20 +09:00
Fujii Hironori
7eff124d09 Remove the unbounded recording surface assertion
There was an assertion in
`_cairo_recording_surface_acquire_source_image` to ensure the surface
isn't unbounded. However, this assertion was failing for
`record-paint` test on Windows.

Removed the assertion and return `CAIRO_INT_STATUS_UNSUPPORTED` if the
surface is unbounded.

Fixes cairo/cairo#619
2023-01-10 13:15:31 +09:00
Adrian Johnson
efe303d9db Remove autotools build 2023-01-08 22:27:47 +10:30
Adrian Johnson
dd8f55100a Require -DDEBUG_ENABLE_COLR_V1 to enable the COLR v1 renderer
Once there is a FreeType release where the COLR v1 API is no longer
marked experimental, we can change this to a version check.
2023-01-08 15:15:13 +10:30
Adrian Johnson
89d004432b COLRv1: Use cairo style and types 2023-01-08 15:15:13 +10:30
Adrian Johnson
2dfc52064e Use cairo-ft-font.c decompose function 2023-01-08 15:15:13 +10:30
Adrian Johnson
1129b194b5 Render COLRv1 to a recording surface 2023-01-08 15:15:13 +10:30
Adrian Johnson
9ed34574a6 Fix a couple of bugs and add a #define to enable debug 2023-01-08 15:15:13 +10:30
Adrian Johnson
3c8dec60e5 Integrate COLR v1 renderer with cairo-ft-font.c 2023-01-08 15:15:13 +10:30
Adrian Johnson
e892d0e92f COLRv1 glyph renderer
Matthias Clasen's COLR v1 glyph renderer from !370
2023-01-08 10:00:29 +10:30
Benjamin Hennion
477c134412 Make _cairo_paginated_surface_set_size takes double-typed width and
height (instead of integers).

    Both cairo_pdf_surface_set_size and cairo_ps_surface_set_size passed on
    their width and height arguments (of type double) directly to
    _cairo_paginated_surface_set_size(cairo_paginated_surface_t*, int, int),
    so the width and height were truncated.
    A small part of the surface was then inaccessible for drawing (stripes
    on the right and bottom of the surface).
    This fixes that.
2023-01-07 13:08:38 +01:00
Uli Schlachter
089cfb5558 Fix docs for cairo_surface_[sg]et_device_scale
Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/616
Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-01-06 18:00:40 +01:00
Uli Schlachter
3a7bb13582 Fix a leak in the cairo-svg-glyph-renderer
This svg

  <svg /><path stroke-dasharray=""fill="url(# "id=""/>

Lead to two memory leaks like the following:

 98 bytes in 98 blocks are definitely lost in loss record 2 of 11
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4EB8789: strdup (strdup.c:42)
    by 0x493C450: save_graphics_state (cairo-svg-glyph-render.c:2894)

This happened because the value of gs->dash_array was replaced without
freeing the previous value. This commit adds the missing free and fixes
the leak.

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54830
Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-01-05 17:14:34 +01:00
Adrian Johnson
13a0474641 Merge branch 'mingw-fixes' into 'master'
Fix mingw build failure when SVG fonts enabled

See merge request cairo/cairo!389
2023-01-03 19:03:50 +00:00
Adrian Johnson
ca0f8ffd84 Merge branch 'foreground-color-in-group' into 'master'
User-fonts fails when foreground color used inside a group

See merge request cairo/cairo!380
2023-01-03 07:45:35 +00:00
Adrian Johnson
f0ce8658f9 Fix user-font with foreground in group failures on image, PDF, and PS 2023-01-03 17:37:36 +10:30
Adrian Johnson
3d102f25c9 Use _cairo_strndup where appropriate 2023-01-03 16:01:51 +10:30
Adrian Johnson
6d03a18649 Fix leak 2023-01-03 15:28:02 +10:30
Adrian Johnson
dcc6c2c806 Fix mingw warning: "ERROR" redefined 2023-01-03 15:27:05 +10:30
Adrian Johnson
5e0e40e3c5 Fix mingw build failure when SVG fonts enabled
Add missing strndup() function. Copied the strndup() implementation
from util/cairo-missing/strndup.c plus a bug fix.
2023-01-03 15:27:03 +10:30
Adrian Johnson
e8b622ebe6 Support check-def.sh in meson build
The original check-def.sh called make. In meson, check-def.sh is
replaced by two shell scripts, one for generating cairo.def, the other
for comparing with the library symbols.

The library filename appended to the cairo.def has been omitted as
this is only reqired in autotools builds where the cairo.def is also
to generate cairo.dll in the windows build.

make-cairo-def.sh is based on the cairo.def target in Makefile.am.
meson-check-def.sh is based on check-def.sh
2023-01-02 22:43:39 +10:30
Uli Schlachter
8dbc5893f7 Merge branch 'jpx-out-of-bounds' into 'master'
Fix possible out-of-bound reads in get_jpx_info

See merge request cairo/cairo!387
2023-01-02 09:28:42 +00:00
Uli Schlachter
e60e562fd1 Fix possible out-of-bound reads in get_jpx_info
Inspired by [1], I looked into the other functions in
cairo-image-info.c. This commit fixes the possible out-of-bound reads
that I found just by staring at the code.

_jpx_next_box() would happily read beyond the end of the data via
get_unaligned_be32(). This commit adds checks that at least for bytes of
data are available.

Additionally, I made this function check that its returned pointer is
within bounds, just because I found this easier to reason about.

Also, _jpx_extract_info() did not check that it had enough data to read.
This is fixed by making the function fallible and giving it information
about the end of data.

[1]: https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/386

Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-01-01 14:01:46 +01:00
Uli Schlachter
d623090b32 Fix an out of bounds read in _jbig2_get_next_segment()
Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38451
Signed-off-by: Uli Schlachter <psychon@znc.in>
2023-01-01 09:43:33 +01:00
Uli Schlachter
7de261b0b1 Merge branch 'script-bug-277' into 'master'
script: Implement device finish

Closes #277

See merge request cairo/cairo!292
2022-12-31 15:13:59 +00:00
Uli Schlachter
c24c657525 Improve cff index reading code
In a recent MR [1], Adrian Johnson writes:

  For additional safety you could change the unsigned long to size_t
  since long is 32-bits on Win64. The CFF spec says the offset size used
  in decode_index_offset must be between 1 and 4 so you could range
  check that to avoid overflowing the offset.

This commit implements exactly that.

[1]: https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/382#note_1700743

Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-12-31 14:21:28 +01:00
Uli Schlachter
c56c3023bb Merge branch 'oob-cff-subset' into 'master'
Fix out-of-bounds access in cff subset

See merge request cairo/cairo!382
2022-12-31 13:20:07 +00:00
Uli Schlachter
cc656934da Fix a possible out-of-bounds read
While working on the previous commit, I noticed that nothing makes sure
that the entry points within the font data. Thus, this could easily
cause out-of-bounds reads.

This commit adds a suitable length check for this.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-12-31 13:43:32 +01:00
Uli Schlachter
52760fc90e Fix out-of-bounds access in cff subset
I was looking at [1]. While trying to reproduce the problem that is
described there, valgrind reported:

 Argument 'size' of function malloc has a fishy (possibly negative) value: -8
    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4B20E92: cairo_cff_font_read_name (cairo-cff-subset.c:895)
    by 0x4B221AD: cairo_cff_font_read_font (cairo-cff-subset.c:1351)
    by 0x4B24EF2: cairo_cff_font_generate (cairo-cff-subset.c:2587)
    by 0x4B25EA3: _cairo_cff_subset_init (cairo-cff-subset.c:2979)

This commit is about fixing the above.

The function decode_index_offset() returns an unsigned long. This value
was cast to an "int" in cff_index_read(), leading to a possibility for
over/underflow. Also, nothing checked that an entry in the index table
had a non-zero length, leading to an entry with length -8 as reported by
valgrind.

Fix this by using "unsigned long" for the local variables and checking
the length to be non-negative.

With the above fixed, the original test case started crashing.
Apparently, cairo_cff_font_read_name() does not expect nor handle
failures from cff_index_read(). Thus, a check for this case was added to
make the new crash go away.

[1]: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=51324

Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-12-31 13:43:24 +01:00
Uli Schlachter
488209d9e9 Fix memory leak in type3 glyph surface
In _cairo_type3_glyph_surface_create(), we call
_cairo_surface_clipper_init(), but nothing ever called
_cairo_surface_clipper_reset() in this call. This commit adds that
missing call.

This fixes a leak of a clip.

Since I have no clue about this code (does _cairo_pdf_operators_fini()
possible use the clipper?), I did the patch like this. This should avoid
any possibility for a use-after-free.

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=51043
Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-12-31 13:30:57 +01:00
Adrian Johnson
3a60f6e138 Merge branch 'ft-svg-fonts' into 'master'
Support SVG fonts in FT backend

See merge request cairo/cairo!319
2022-12-31 09:27:57 +00:00
Uli Schlachter
a2d05a0c34 ps: Fix crash in self-copy-overlap
According to valgrind, there is a use-after-free here. The function
_cairo_ps_surface_emit_surface() temporarily replaces some member of a
struct and then later re-sets it. However, there is an early return
possible that would skip that part of the code.

This commit moves the re-set up so that no freed pointers are left
behind. This seems to fix the crash.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-12-28 11:15:01 +01:00