[cairo] cairo_image_surface_create(), limited width

Stanisław Jeśmanowicz stan at jesmanowicz.com
Thu Aug 6 10:34:11 UTC 2020


Hello,

This simple patch fix the problem, at least  for lot of cases:

diff -ur cairo-1.17.3.org/src/cairo-image-surface.c
cairo-1.17.3/src/cairo-image-surface.c
--- cairo-1.17.3.org/src/cairo-image-surface.c  2020-08-01
21:39:54.382864735 +0200
+++ cairo-1.17.3/src/cairo-image-surface.c      2020-08-06
12:23:22.815177003 +0200
@@ -85,8 +85,8 @@
 static cairo_bool_t
 _cairo_image_surface_is_size_valid (int width, int height)
 {
-    return 0 <= width  &&  width <= MAX_IMAGE_SIZE &&
-          0 <= height && height <= MAX_IMAGE_SIZE;
+    return ((0 <= width) && (width <= MAX_IMAGE_SIZE) &&
+          (0 <= height) && (height <= MAX_IMAGE_SIZE));
 }
 
 cairo_format_t

 
Regards,
Stan

On 03-08-2020 17:23, Uli Schlachter wrote:
> Hi,
>
> Am 03.08.20 um 16:32 schrieb Stanisław Jeśmanowicz:
>> On 03-08-2020 15:36, Uli Schlachter wrote:
>>> Am 02.08.20 um 13:25 schrieb Stanisław Jeśmanowicz:
> [...]
>>>> - Do we really need this conservative  check
>>>> (_cairo_image_surface_is_size_valid()) ?
>>> Uhm, yes. What use is a large surface if you cannot draw to parts of it?
>> I can imagine that large surface can be a problem, although only host
>> computer memory is the limit.
>> 32767 x 32767 is roughly 1GB.
> This is not about "large" as in "uses a lot of memory". This is about
> "large" as in "has a large width *OR* a large height", larger than what
> we can draw to.
>
> A surface with size 10000000 x 1 does not use much memory (I assume - no
> idea which number key repeat ended up producing here).
> Let us now try to draw to it. We want the last few pixels to be filled:
>
> cairo_rectangle(cr, 10000000 - 42, 0, 42, 1);
> cairo_fill(cr);
>
> This now tries to draw to a coordinate that is larger than 16 bits. This
> means that when calling pixman to do the actual drawing, an integer
> overflow happens. The rectangle will actually be drawn at the requested
> coordinate modulo 2^16.
>
> This is what I mean with "Pixman uses a fixed point format for
> specifying coordinates. 16 bits specify the integer part and 16 bits
> specify the fractional part."
>
> Cheers,
> Uli


-- 
__________________________________________________________

Stanislaw Jesmanowicz      stan <at> jesmanowicz <dot> com
Amsterdam                  voice : + 31 20 6126193
The Netherlands            mobile: + 31  653380520 



More information about the cairo mailing list