Commit graph

84 commits

Author SHA1 Message Date
Adrian Johnson
0cae2a4a74 Use _cairo_calloc() to allocate structs
To avoid any possibility of uninitialized memory.

The exceptions are:
 - where the allocation is immediately overwritten by a memcpy or struct copy.
 - arrays of structs to avoid any performance impact (except when the
   array is returned by the public API).
2024-06-21 10:32:23 +09:30
Uli Schlachter
6a81bf8201 script: Implement device finish
Before this commit, calling cairo_device_finish() on a cairo-script
context did not actually do anything in the backend. Thus, it was
possible to continue emitting output on the script context even after it
was finished, which means that API user had no way of preventing
use-after-free bugs in their write callback. Bug 277 triggers this via
detaching a snapshot, but I guess one could also simply continue drawing
to a script surface.

This commit implements the finish function by closing the underlying
stream.

However, that was not enough to fix things. This commit also turns
writing into a stream into a no-op after the stream was closed.

I checked that the new test case actually fails before this commit and
is indeed fixed by it.

Fixes: https://gitlab.freedesktop.org/cairo/cairo/-/issues/277
Signed-off-by: Uli Schlachter <psychon@znc.in>
2022-03-08 18:11:23 +01:00
Adrian Johnson
6e3c7431ff Allow > 2GB PDF files on platforms with 32-bit long 2021-09-02 18:39:53 +09:30
Paul Menzel
f246a2144f Use HTTPS URLs for gnome.org domains
Run the command below suggested by geirha in ##sed@irc.freenode.net.

    git grep -l 'http://.*gnome.org' | xargs sed -i 's|http\(://\([[:alnum:].-]*\.\)\{0,1\}gnome\.org\)|https\1|g'

Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
2018-10-16 10:03:20 -07:00
Adrian Johnson
1998239387 Use _cairo_malloc instead of malloc
_cairo_malloc(0) always returns NULL, but has not been used
consistently.  This patch replaces many calls to malloc() with
_cairo_malloc().

Fixes:  fdo# 101547
CVE: CVE-2017-9814 Heap buffer overflow at cairo-truetype-subset.c:1299
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2018-05-07 16:35:51 -07:00
Tom Schoonjans
84fc0ce91d Use UTF-8 filenames on Windows
Until now fopen was used on Windows to open files for reading and
writing. This assumed however that the filename would be encoded in the
current codepage, which is a major inconvenience and makes it even
impossible to use filenames that use characters from more than one
codepage. This patch enforces the use of UTF-8 filenames on all
platforms.

Based on the work of Owen Taylor (https://lists.cairographics.org/archives/cairo/2007-February/009591.html)
2017-11-26 20:16:43 +10:30
Adrian Johnson
202a9ed64e output-stream: allow %s strings larger than 512 chars
https://bugs.freedesktop.org/show_bug.cgi?id=103249
2017-10-13 19:33:30 +10:30
Adrian Johnson
e773dd744e factor out ascii to double code in cff-subset into _cairo_strtod 2017-09-22 18:17:25 +09:30
Adrian Johnson
1220e3c6b8 replace _BSD_SOURCE with _DEFAULT_SOURCE
fixes the warning:

warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
2017-09-16 10:04:57 +09:30
Adrian Johnson
9a19ef1858 Fix compilation with bionic libc
Refactor out a cairo_get_locale_decimal_point() routine to handle a case
where localeconv() is not available.

Fixes:  https://bugs.freedesktop.org/show_bug.cgi?id=70492
Reviewed-by: Bryce Harrington <b.harrington@samsung.com>

[edit:  Condensed cairo_get_locale_decimal_point and conditionalized
locale.h inclusion.  -- bryce]
2014-09-23 11:40:03 -07:00
Adrian Johnson
dcbe16eb40 pdf/ps: avoid outputting excess decimal places in matrices
Sometimes as a result of rounding errors in matrix transformations the
matrices in ps/pdf output look like:

    0.000000000000000061 1 1 -0.000000000000000061 0 842 cm

This patch rounds to zero matrix elements that are very small compared to
other elements in the same matrix.
2013-12-07 15:54:49 +10:30
Chris Wilson
af9fbd176b Introduce a new compositor architecture
Having spent the last dev cycle looking at how we could specialize the
compositors for various backends, we once again look for the
commonalities in order to reduce the duplication. In part this is
motivated by the idea that spans is a good interface for both the
existent GL backend and pixman, and so they deserve a dedicated
compositor. xcb/xlib target an identical rendering system and so they
should be using the same compositor, and it should be possible to run
that same compositor locally against pixman to generate reference tests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

P.S. This brings massive upheaval (read breakage) I've tried delaying in
order to fix as many things as possible but now this one patch does far,
far, far too much. Apologies in advance for breaking your favourite
backend, but trust me in that the end result will be much better. :)
2011-09-12 08:29:48 +01:00
Chris Wilson
9b9952ab4f Convert mime data length to use unsigned long
What we want to use is size_t, but we don't want the implied POSIX
dependency. However, POSIX does say that size_t is an unsigned integer
that is no longer than a long, so it would appear safe to use an
unsigned long as a replacement. Safer at least than unsigned int.
2010-07-10 11:16:19 +01:00
Andrea Canciani
b8a7f8621a Update FSF address
I updated the Free Software Foundation address using the following script.

for i in $(git grep Temple | cut -d: -f1 )
do
  sed -e 's/59 Temple Place[, -]* Suite 330, Boston, MA *02111-1307[, ]* USA/51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA/' -i "$i"
done

Fixes http://bugs.freedesktop.org/show_bug.cgi?id=21356
2010-04-27 11:13:38 +02:00
Chris Wilson
c50c8b90c0 Move _cairo_error() to a standalone header
A pending commit will want to include some utility code from cairo and
so we need to extricate the error handling from the PLT symbol hiding.
2010-01-22 22:30:43 +00:00
Adrian Johnson
600dd83398 Provide a builtin implementation of isspace() and isdigit()
The glibc versions are slow in utf8 locales.
2009-10-29 22:05:19 +10:30
Chris Wilson
e6963a5bfe Mark allocation failures as unlikely.
Use the gcc likelihood annotation to indicate that allocation failures are
extremely unlikely.
2008-11-29 11:20:34 +00:00
Chris Wilson
d1801c23fa Mark if(status) as being unlikely.
The error paths should be hit very rarely during normal operation, so mark
them as being unlikely so gcc may emit better code.
2008-11-29 11:20:33 +00:00
Chris Wilson
a856371bef Add CairoScript backend.
A new meta-surface backend for serialising drawing operations to a
CairoScript file. The principal use (as currently envisaged) is to provide
a round-trip testing mechanism for CairoScript - i.e. we can generate
script files for every test in the suite and check that we can replay them
with perfect fidelity. (Obviously this does not provide complete coverage
of CairoScript's syntax, but should give reasonable coverage over the
operators.)
2008-11-13 11:36:54 +00:00
Chris Wilson
e40d62a0fe [png] Attach the png representation to cairo_surface_create_from_png().
Attach the original png data as an alternate representation for image
surfaces created by cairo_surface_create_from_png().
2008-11-05 18:13:09 +00:00
Chris Wilson
41c8eefc6d [output-stream] Protect against NULL write_func.
Allow the user to specify a NULL write_func for the output stream so that
a dummy surface can be created, for example, for querying target font
options or font extents.

Currently we do not perform any sanity checks at the user entry point and
will generate a mysterious SEGV during cairo_surface_finish() - which may
not immediately be obvious that it is due to a NULL write_func.
2008-10-19 09:36:53 +01:00
Chris Wilson
84e4a825ff [output-stream] Accept a NULL filename
Principally to support creating a dummy vector surface (i.e.
cairo_ps_surface_create (NULL, 1, 1)) that can be used to determine font
extents (or target font options) before opening an output file, but also
because we currently fail to do any sanity checking at the entry point.
2008-10-19 09:36:53 +01:00
Adrian Johnson
b74533b5a5 Add null output stream 2008-09-11 08:37:30 +09:30
Chris Wilson
de6742c5f1 [ps] Mark the hex data as unsigned char.
Use unsigned char to avoid sign extensions issues when bit shifting.
2008-08-26 23:02:41 +01:00
Chris Wilson
e3b6a0c89a [cairo-output-stream] Dead store.
Value stored to 'p' is never read.
2008-08-17 14:44:44 +01:00
Behdad Esfahbod
5f63358018 [src/check-doc-syntax.sh] Fix some bugs in the check and fix errors found 2008-05-09 15:54:04 +02:00
Adrian Johnson
d78013470b Add %g conversion specifer to output-stream for limited precision
The %g conversion specifier is for printing numbers that were at some
time stored in a cairo_fixed_t type and as a result have their
precision limited by the size of CAIRO_FIXED_FRAC_BITS.

Using %g will limit the number of digits after the decimal point to
the minimum required to preserve the available precision.
2008-03-20 18:15:10 +10:30
Adrian Johnson
f3734085a1 Make _cairo_dtostr() static
It is only used in cairo-output-stream.c
2008-03-20 18:15:09 +10:30
Chris Wilson
222eb6f140 Define _BSD_SOURCE to enable prototypes for strdup, snprintf.
strdup() and friends require at least _BSD_SOURCE or
_XOPEN_SOURCE >= 500 to be defined for the prototypes to be included.
For the time being, add the define to each source file that requires one
of the BSD functions.
2008-03-12 17:52:16 +00:00
Jody Goldberg
4c7784e91e Fix PDF ouput when cross-compiling with mingw
Need to use __WIN32__ instead of _MSC_VER to select _snprintf in
place of snprintf when cross compiling. Otherwise all all %ld
arguments get misprinted resulting in broken PDF output.
2008-02-28 15:23:53 -08:00
Behdad Esfahbod
f0633f4449 [doc] Make sure all function names in docs are followed by () 2008-01-28 21:49:57 -05:00
Chris Wilson
5cbc45488e [cairo-output-stream] Introduce _cairo_output_stream_create_in_error()
Use a utility function to wrap an incoming error status into a new
error stream. As a side-effect, all error streams must be destroyed as
in the general case the caller can not distinguish between a static
error object and one allocated to hold an unusual error status.
2008-01-16 16:40:01 +00:00
Chris Wilson
f440d894e6 Check errno for appropriate error return.
After using fopen() and friends check the global errno to determine the
most  appropriate error return - especially important when running
memfault, where correct reporting of NO_MEMORY errors is required.
2008-01-05 21:25:30 +00:00
Adrian Johnson
c37a8ace81 Round floats in output-stream to 6 significant digits after decimal
The previous commit increased the precision of floats from 6 digits
after the decimal point to 18 digits to correct rounding errors with
very small numbers. However most of the time this extra precision is
not required and results in increased PS/PDF output.

This commit makes the precision after the decimal point 6 significant
digits. For example:

   1.234567
   0.123456
   0.00123456
   0.00000000123456
2007-11-01 00:01:16 +10:30
Behdad Esfahbod
8297daff89 [cairo-output-stream] Write out floats to 18 digits after decimal point
We write floats using %f as the scientific format used by smarter %g is
invalid in PS/PDF.  %f however by default rounds to five digits after
decimal point.  This was causing precision loss and making the newly
added degenerate-pen test fail for PDF.  We now print up to 18 digits
which is as many bits doubles can accomodate.  We can be smarter, but
that's for another commit.
2007-10-31 02:41:33 -04:00
Chris Wilson
353c2ab5c0 [cairo-output-stream] Guard against destroying the nil streams.
Add a guard to return early if we attempt to call
_cairo_output_stream_destroy() on the nil cairo_output_stream_t streams.
2007-10-04 20:07:58 +01:00
Chris Wilson
de1f92ae14 [cairo-output-stream] Propagate error status when copying streams.
During _cairo_memory_stream_copy(), if set, copy the incoming error over
to the destination stream and return early.
2007-10-04 14:51:16 +01:00
Chris Wilson
bed8239f03 [cairo-error] Clean up all the warnings and missing _cairo_error() calls.
Every time we assign or return a hard-coded error status wrap that value
with a call to _cairo_error(). So the idiom becomes:
    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
or
    return _cairo_error (CAIRO_STATUS_INVALID_DASH);

This ensures that a breakpoint placed on _cairo_error() will trigger
immediately cairo detects the error.
2007-10-04 13:31:44 +01:00
Chris Wilson
8ad56b308a [malloc/error] Add call to _cairo_error() after a failed malloc.
Blitz all allocations to ensure that they raise a
_cairo_error(CAIRO_STATUS_NO_MEMORY) on failure.
2007-10-04 00:42:30 +01:00
Adrian Johnson
ca3662d6fc Make cairo-output-stream.c accept variable width printf fields 2007-04-20 22:43:37 +09:30
Carl Worth
b0a256aaf3 Change _cairo_dtostr to have a void return type
As previously implemented, there's no essential information in the
return value from _cairo_dotostr, (the caller can simply use strlen
to recompute the same value, which is what the only caller is already
doing).

There would be real information in a return value which would return
the result from the call to snprintf for the case where the buffer is
not large enough for the number being printed.
2007-04-10 13:07:09 -07:00
Carl Worth
5303980f82 _cairo_output_stream_vprintf: Add assertion to detect internal inconsitency
This will catch any inconsistency between the length of a single
format specifier and the fixed size of the single_fmt buffer.
2007-04-10 13:03:37 -07:00
Carl Worth
97a69bc82e Fix mis-indented _cairo_dtostr 2007-04-10 12:13:27 -07:00
Behdad Esfahbod
8fbf50d31d [src] Make sure all source files #include "cairoint.h" as their first include
This is necessary to avoid many portability problems as cairoint.h includes
config.h.  Without a test, we will regress again, hence add it.

The inclusion idiom for cairo now is:

	#include "cairoint.h"

	#include "cairo-something.h"
	#include "cairo-anotherthing-private.h"

	#include <some-library.h>
	#include <other-library/other-file.h>

Moreover, some standard headers files are included from cairoint.h and need
not be included again.
2007-04-03 20:28:11 -04:00
Behdad Esfahbod
88dc0c5f19 Make sure all nil objects start with _cairo_
Previously, the convention was that static ones started with cairo_, but
renamed to start with _cairo_ when they were needed from other files and
became cairo_private instead of static...

This is error prune indeed, and two symbols were already violating.  Now
all nil objects start with _cairo_.
2007-04-03 19:26:18 -04:00
Jeff Smith
5f83a1b542 [cairo-output-stream] Remove use of strtol 2007-03-21 10:41:03 -04:00
Adrian Johnson
88cae7766d output-stream: coding style fix 2007-02-13 23:29:05 +10:30
Adrian Johnson
d6f15b2600 Output-stream: Omit the minus sign from negative zero 2007-02-11 22:20:58 +10:30
Carl Worth
89e7d5d420 Make _cairo_output_stream_destroy return the stream's status as a last gasp. 2006-09-07 16:01:07 -07:00
Carl Worth
959b85e98c Merge branch 'warnings-cleanup' into cairo
Conflicts:

	src/cairo-font-subset.c
2006-08-07 15:06:47 -07:00