[Poppler-bugs] [Bug 44002] drawImage uses a too large area when in printing mode

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Mon Jan 9 09:08:01 PST 2012


https://bugs.freedesktop.org/show_bug.cgi?id=44002

--- Comment #5 from Benjamin Berg <benjamin at sipsolutions.net> 2012-01-09 09:08:01 PST ---
As the history of the comments seems to confuse people, here a go at a self
contained explanation.

Short version (which hopefully should be enough):

Commit d63293af6 (Carlos Garcia Campos, Turn EXTEND_PAD off when printing) did
the following change:
-  cairo_rectangle (cairo, 0., 0., 1., 1.);
+  if (printing)
+    cairo_rectangle (cairo, 0., 0., width, height);
+  else
+    cairo_rectangle (cairo, 0., 0., 1., 1.);

In the "printing" case, this results in a clip area that is very large (ie.
dest_width * image_width, dest_height * image_height; where
dest_width/dest_height is from the current transformation matrix).

So, just removing the special case will fix the problem. Another way to fix it
would be to replace the "printing" case with a cairo_paint, as the extend mode
is CAIRO_EXTEND_NONE for the "printing" case; this could be more in the spirit
of the commit by Carlos.

----

Long version:

So as I understand it:
 1. In a PDF an image will always be drawn in the rectangle (0, 0, 1, 1), and
the size is specified by changing the transformation matrix.
 2. Poppler transforms the patterns matrix, so that the image is mapped into
this space. This happens in line 2765 and following:

>  cairo_matrix_init_translate (&matrix, 0, height);
>  cairo_matrix_scale (&matrix, image_width, -image_height);
>  cairo_pattern_set_matrix (pattern, &matrix);

 3. A draw_rectangle in the rectangle (0, 0, 1, 1) is done. (Line 2785)

Now, when poppler is in printing mode, the last point fails. Instead of drawing
in the area (0, 0, 1, 1) it draws in the area (0, 0, image_width,
image_height). This rectangle is then multiplied with the current
transformation matrix (scaling it by ~595 and ~842 for a whole A4 page).

To be exact, look at the following output:
q
0 841.89 595 -841 re W n
q
0 4058686.144 2037628.645 -4058684.387 re W n
595.275678 0 0 840.133386 0 1.756407 cm
/a0 gs /x11 Do
Q
Q

The image has the size of 3423x4831 pixel. This is multiplied by the above
matrix:
  3423 * 595.275678 = 2037628.645794
  4831 * 840.133386 = 4058684.387766

As one can see, this gives us the values from the way too large clip rectangle.


Once you have these huge numbers in a PDF, you can easily overflow cairo by
rendering this at 300 DPI to an image surface. It means the clip region gets a
size of:
  4058684.387766 pt * 300px / 72pt = 16911184.949025 px
Which is much larger than 2^23.

-- 
Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Poppler-bugs mailing list