Skip to content

Commit

Permalink
enlarge canvas fixes
Browse files Browse the repository at this point in the history
We can crash darktable being in darkroom using the enlarge_canvas module while being zoomed in either in
process() or in distort_mask()

Both are related to incorrect results for border_in_x/y leading to out-of-bounds data access.
So we restrict results to be in allowed range.

Use dt_aligned_pixel_t instead of float[4] as used elsewhere.
  • Loading branch information
jenshannoschwalm authored and TurboGit committed Jan 22, 2025
1 parent b36b483 commit b86e4fb
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/iop/enlargecanvas.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2024 darktable developers.
Copyright (C) 2024-25 darktable developers.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -306,14 +306,14 @@ void distort_mask(dt_iop_module_t *self,

dt_iop_border_positions_t binfo;

float bcolor[4] = { 0 };
float fcolor[4] = { 0 };
dt_aligned_pixel_t bcolor = { 0 };
dt_aligned_pixel_t fcolor = { 0 };

dt_iop_setup_binfo(piece, roi_in, roi_out, pos_v, pos_h,
bcolor, fcolor, 0.f, 0.f, &binfo);

const int border_in_x = binfo.border_in_x;
const int border_in_y = binfo.border_in_y;
const int border_in_x = CLAMP(binfo.border_in_x, 0, roi_out->width - roi_in->width);
const int border_in_y = CLAMP(binfo.border_in_y, 0, roi_out->height - roi_in->height);

// fill the image with 0 so that the added border isn't part of the mask
dt_iop_image_fill(out, 0.0f, roi_out->width, roi_out->height, 1);
Expand Down Expand Up @@ -342,8 +342,8 @@ void process(dt_iop_module_t *self,

_compute_pos(d, &pos_v, &pos_h);

float fcolor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
float bcolor[4];
dt_aligned_pixel_t fcolor = { 1.0f, 1.0f, 1.0f, 1.0f };
dt_aligned_pixel_t bcolor;

bcolor[3] = 1.0f;

Expand Down Expand Up @@ -385,6 +385,9 @@ void process(dt_iop_module_t *self,
dt_iop_setup_binfo(piece, roi_in, roi_out, pos_v, pos_h,
bcolor, fcolor, 0.f, 0.f, &binfo);

binfo.border_in_x = CLAMP(binfo.border_in_x, 0, roi_out->width - roi_in->width);
binfo.border_in_y = CLAMP(binfo.border_in_y, 0, roi_out->height - roi_in->height);

dt_iop_copy_image_with_border((float*)ovoid, (const float*)ivoid, &binfo);
}

Expand Down

0 comments on commit b86e4fb

Please sign in to comment.