From 76b896da1a4dafaa71214bc520d0f07de94ce7c1 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 11 Nov 2012 18:45:51 +1030 Subject: [PATCH 1/2] pdftocairo: cairo does not allow image width/height > 32767 Bug 56858 --- utils/pdftocairo.cc | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index 8d13e31..a9fb425 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -68,6 +68,11 @@ #include #endif +/* Limit on the width / height of a cairo image surface in pixels. This + * is due to the 16.16 format used by pixman. + */ +#define MAX_IMAGE_SIZE 32767 + static GBool png = gFalse; static GBool jpeg = gFalse; @@ -471,7 +476,7 @@ static void beginDocument(GooString *outputFileName, double w, double h) } } -static void beginPage(double w, double h) +static void beginPage(int pg, double page_w, double page_h, double w, double h) { if (printing) { if (ps || eps) { @@ -494,7 +499,13 @@ static void beginPage(double w, double h) cairo_surface_set_fallback_resolution (surface, x_resolution, y_resolution); } else { - surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ceil(w), ceil(h)); + if (w > MAX_IMAGE_SIZE || h > MAX_IMAGE_SIZE) { + fprintf(stderr, "Error: Page %d output too large. Page size: %.0fx%.0f points. Output size %.0fx%.0f pixels\n", pg, ceil(page_w), ceil(page_h), ceil(w), ceil(h)); + fprintf(stderr, "Maximum cairo image width and height is %d pixels.\n", MAX_IMAGE_SIZE); + surface = NULL; + } else { + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ceil(w), ceil(h)); + } } } @@ -506,6 +517,9 @@ static void renderPage(PDFDoc *doc, CairoOutputDev *cairoOut, int pg, cairo_status_t status; cairo_matrix_t m; + if (!surface) + return; + cr = cairo_create(surface); cairoOut->setCairo(cr); cairoOut->setPrinting(printing); @@ -558,6 +572,9 @@ static void endPage(GooString *imageFileName) { cairo_status_t status; + if (!surface) + return; + if (printing) { cairo_surface_show_page(surface); } else { @@ -978,7 +995,7 @@ int main(int argc, char *argv[]) { if (pg == firstPage) beginDocument(outputFileName, output_w, output_h); - beginPage(output_w, output_h); + beginPage(pg, pg_w, pg_h, output_w, output_h); renderPage(doc, cairoOut, pg, pg_w, pg_h, output_w, output_h); endPage(imageFileName); } -- 1.7.10.4