[gthumb] jpeg loader: do not scan more than output_height lines



commit 4faa5ce2358812d23a1147953ee76f59631590ad
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Dec 16 17:54:56 2019 +0100

    jpeg loader: do not scan more than output_height lines

 extensions/cairo_io/cairo-image-surface-jpeg.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/extensions/cairo_io/cairo-image-surface-jpeg.c b/extensions/cairo_io/cairo-image-surface-jpeg.c
index 7bdef9e3..8ab26fd2 100644
--- a/extensions/cairo_io/cairo-image-surface-jpeg.c
+++ b/extensions/cairo_io/cairo-image-surface-jpeg.c
@@ -173,6 +173,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
        unsigned char                 *surface_row;
        JSAMPARRAY                     buffer;
        int                            buffer_stride;
+       int                            scanned_lines;
        JDIMENSION                     n_lines;
        JSAMPARRAY                     buffer_row;
        int                            l;
@@ -298,6 +299,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
        _cairo_metadata_set_has_alpha (metadata, FALSE);
        surface_data = _cairo_image_surface_flush_and_get_data (surface);
        surface_row = surface_data + line_start;
+       scanned_lines = 0;
 
        switch (srcinfo.out_color_space) {
        case JCS_CMYK:
@@ -313,6 +315,8 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
                                        goto stop_loading;
 
                                n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
+                               if (scanned_lines + n_lines > output_height)
+                                       n_lines = output_height - scanned_lines;
 
                                buffer_row = buffer;
                                for (l = 0; l < n_lines; l++) {
@@ -349,6 +353,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
 
                                        surface_row += line_step;
                                        buffer_row += buffer_stride;
+                                       scanned_lines += 1;
                                }
                        }
                }
@@ -361,6 +366,8 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
                                        goto stop_loading;
 
                                n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
+                               if (scanned_lines + n_lines > output_height)
+                                       n_lines = output_height - scanned_lines;
 
                                buffer_row = buffer;
                                for (l = 0; l < n_lines; l++) {
@@ -381,6 +388,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
 
                                        surface_row += line_step;
                                        buffer_row += buffer_stride;
+                                       scanned_lines += 1;
                                }
                        }
                }
@@ -393,6 +401,8 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
                                        goto stop_loading;
 
                                n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
+                               if (scanned_lines + n_lines > output_height)
+                                       n_lines = output_height - scanned_lines;
 
                                buffer_row = buffer;
                                for (l = 0; l < n_lines; l++) {
@@ -415,6 +425,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
 
                                        surface_row += line_step;
                                        buffer_row += buffer_stride;
+                                       scanned_lines += 1;
                                }
                        }
                }
@@ -440,6 +451,8 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
                                        goto stop_loading;
 
                                n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
+                               if (scanned_lines + n_lines > output_height)
+                                       n_lines = output_height - scanned_lines;
 
                                buffer_row = buffer;
                                for (l = 0; l < n_lines; l++) {
@@ -466,6 +479,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
 
                                        surface_row += line_step;
                                        buffer_row += buffer_stride;
+                                       scanned_lines += 1;
                                }
                        }
                }
@@ -495,6 +509,8 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
                                        goto stop_loading;
 
                                n_lines = jpeg_read_scanlines (&srcinfo, buffer, srcinfo.rec_outbuf_height);
+                               if (scanned_lines + n_lines > output_height)
+                                       n_lines = output_height - scanned_lines;
 
                                buffer_row = buffer;
                                for (l = 0; l < n_lines; l++) {
@@ -528,6 +544,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
 
                                        surface_row += line_step;
                                        buffer_row += buffer_stride;
+                                       scanned_lines += 1;
                                }
                        }
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]