c2e870
From 8122f6d6d409b53151a20c5578fc525ee97315e8 Mon Sep 17 00:00:00 2001
c2e870
From: Marek Kasik <mkasik@redhat.com>
c2e870
Date: Thu, 21 Mar 2019 13:47:51 +0100
c2e870
Subject: [PATCH 2/2] cairo: Constrain number of cycles in rescale filter
c2e870
c2e870
Pass address of the first byte after end of the source buffer
c2e870
to downsample_row_box_filter() so that we can check
c2e870
that we don't run out of it.
c2e870
c2e870
Fixes issue #736
c2e870
---
c2e870
 poppler/CairoRescaleBox.cc | 18 +++++++++---------
c2e870
 1 file changed, 9 insertions(+), 9 deletions(-)
c2e870
c2e870
diff --git a/poppler/CairoRescaleBox.cc b/poppler/CairoRescaleBox.cc
c2e870
index d7615010..7fd07041 100644
c2e870
--- a/poppler/CairoRescaleBox.cc
c2e870
+++ b/poppler/CairoRescaleBox.cc
c2e870
@@ -62,7 +62,7 @@
c2e870
 
c2e870
 static void downsample_row_box_filter (
c2e870
         int start, int width,
c2e870
-        uint32_t *src, uint32_t *dest,
c2e870
+        uint32_t *src, uint32_t *src_limit, uint32_t *dest,
c2e870
         int coverage[], int pixel_coverage)
c2e870
 {
c2e870
     /* we need an array of the pixel contribution of each destination pixel on the boundaries.
c2e870
@@ -90,13 +90,13 @@ static void downsample_row_box_filter (
c2e870
     /* skip to start */
c2e870
     /* XXX: it might be possible to do this directly instead of iteratively, however
c2e870
      * the iterative solution is simple */
c2e870
-    while (x < start)
c2e870
+    while (x < start && src < src_limit)
c2e870
     {
c2e870
         int box = 1 << FIXED_SHIFT;
c2e870
         int start_coverage = coverage[x];
c2e870
         box -= start_coverage;
c2e870
         src++;
c2e870
-        while (box >= pixel_coverage)
c2e870
+        while (box >= pixel_coverage && src < src_limit)
c2e870
         {
c2e870
             src++;
c2e870
             box -= pixel_coverage;
c2e870
@@ -104,7 +104,7 @@ static void downsample_row_box_filter (
c2e870
         x++;
c2e870
     }
c2e870
 
c2e870
-    while (x < start + width)
c2e870
+    while (x < start + width && src < src_limit)
c2e870
     {
c2e870
         uint32_t a = 0;
c2e870
         uint32_t r = 0;
c2e870
@@ -121,7 +121,7 @@ static void downsample_row_box_filter (
c2e870
         x++;
c2e870
         box -= start_coverage;
c2e870
 
c2e870
-        while (box >= pixel_coverage)
c2e870
+        while (box >= pixel_coverage && src < src_limit)
c2e870
         {
c2e870
             a += ((*src >> 24) & 0xff) * pixel_coverage;
c2e870
             r += ((*src >> 16) & 0xff) * pixel_coverage;
c2e870
@@ -135,7 +135,7 @@ static void downsample_row_box_filter (
c2e870
         /* multiply by whatever is leftover
c2e870
          * this ensures that we don't bias down.
c2e870
          * i.e. start_coverage + n*pixel_coverage + box == 1 << 24 */
c2e870
-        if (box > 0)
c2e870
+        if (box > 0 && src < src_limit)
c2e870
         {
c2e870
             a += ((*src >> 24) & 0xff) * box;
c2e870
             r += ((*src >> 16) & 0xff) * box;
c2e870
@@ -337,7 +337,7 @@ bool CairoRescaleBox::downScaleImage(unsigned orig_width, unsigned orig_height,
c2e870
     int start_coverage_y = y_coverage[dest_y];
c2e870
 
c2e870
     getRow(src_y, scanline);
c2e870
-    downsample_row_box_filter (start_column, width, scanline, temp_buf + width * columns, x_coverage, pixel_coverage_x);
c2e870
+    downsample_row_box_filter (start_column, width, scanline, scanline + orig_width, temp_buf + width * columns, x_coverage, pixel_coverage_x);
c2e870
     columns++;
c2e870
     src_y++;
c2e870
     box -= start_coverage_y;
c2e870
@@ -345,7 +345,7 @@ bool CairoRescaleBox::downScaleImage(unsigned orig_width, unsigned orig_height,
c2e870
     while (box >= pixel_coverage_y)
c2e870
     {
c2e870
       getRow(src_y, scanline);
c2e870
-      downsample_row_box_filter (start_column, width, scanline, temp_buf + width * columns, x_coverage, pixel_coverage_x);
c2e870
+      downsample_row_box_filter (start_column, width, scanline, scanline + orig_width, temp_buf + width * columns, x_coverage, pixel_coverage_x);
c2e870
       columns++;
c2e870
       src_y++;
c2e870
       box -= pixel_coverage_y;
c2e870
@@ -355,7 +355,7 @@ bool CairoRescaleBox::downScaleImage(unsigned orig_width, unsigned orig_height,
c2e870
     if (box > 0)
c2e870
     {
c2e870
       getRow(src_y, scanline);
c2e870
-      downsample_row_box_filter (start_column, width, scanline, temp_buf + width * columns, x_coverage, pixel_coverage_x);
c2e870
+      downsample_row_box_filter (start_column, width, scanline, scanline + orig_width, temp_buf + width * columns, x_coverage, pixel_coverage_x);
c2e870
       columns++;
c2e870
     }
c2e870
 
c2e870
-- 
c2e870
2.20.1
c2e870