Commit 31d2d1e4 authored by Clint Rogers's avatar Clint Rogers

3656 - Prevents crashing by adding protection against drawing or sampling...

3656 - Prevents crashing by adding protection against drawing or sampling 0-pixel sized regions (GTK hates these).
parent 1e561d43
......@@ -571,7 +571,10 @@ public struct ZoomState {
if (bottom > zoomed_height)
bottom = zoomed_height;
result.height = bottom - result.y;
result.width = result.width.clamp(1, int.MAX);
result.height = result.height.clamp(1, int.MAX);
return result;
}
......
......@@ -1920,14 +1920,17 @@ public abstract class SinglePhotoPage : Page {
zoomed = proj_subpixbuf.scale_simple(view_rect.width, view_rect.height,
Gdk.InterpType.BILINEAR);
}
if (zoomed == null) {
return;
}
int draw_x = (pixmap_dim.width - view_rect.width) / 2;
if (draw_x < 0)
draw_x = 0;
int draw_y = (pixmap_dim.height - view_rect.height) / 2;
if (draw_y < 0)
draw_y = 0;
draw_x = draw_x.clamp(0, int.MAX);
int draw_y = (pixmap_dim.height - view_rect.height) / 2;
draw_y = draw_y.clamp(0, int.MAX);
Gdk.cairo_set_source_pixbuf(pixmap_ctx, zoomed, draw_x, draw_y);
pixmap_ctx.paint();
}
......
......@@ -161,12 +161,23 @@ public class ZoomBuffer : Object {
view_rect_proj.height /= 2;
}
// On very small images, it's possible for these to
// be 0, and GTK doesn't like sampling a region 0 px
// across.
view_rect_proj.width = view_rect_proj.width.clamp(1, int.MAX);
view_rect_proj.height = view_rect_proj.height.clamp(1, int.MAX);
view_rect.width = view_rect.width.clamp(1, int.MAX);
view_rect.height = view_rect.height.clamp(1, int.MAX);
Gdk.Pixbuf proj_subpixbuf = new Gdk.Pixbuf.subpixbuf(sample_source_pixbuf, view_rect_proj.x,
view_rect_proj.y, view_rect_proj.width, view_rect_proj.height);
Gdk.Pixbuf zoomed = proj_subpixbuf.scale_simple(view_rect.width, view_rect.height,
Gdk.InterpType.BILINEAR);
assert(zoomed != null);
return zoomed;
}
......@@ -286,6 +297,9 @@ public class ZoomBuffer : Object {
Gdk.Rectangle view_rect_proj = zoom_state.get_viewing_rectangle_projection(
preview_image);
view_rect_proj.width = view_rect_proj.width.clamp(1, int.MAX);
view_rect_proj.height = view_rect_proj.height.clamp(1, int.MAX);
Gdk.Pixbuf proj_subpixbuf = new Gdk.Pixbuf.subpixbuf(preview_image,
view_rect_proj.x, view_rect_proj.y, view_rect_proj.width, view_rect_proj.height);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment