Skip to content

Fix crash in scalepixels when used with rotate-and-perspective module#20706

Open
da-phil wants to merge 1 commit intodarktable-org:masterfrom
da-phil:fix_crash_in_scalepixels_when_rotation_and_cropping_is_active
Open

Fix crash in scalepixels when used with rotate-and-perspective module#20706
da-phil wants to merge 1 commit intodarktable-org:masterfrom
da-phil:fix_crash_in_scalepixels_when_rotation_and_cropping_is_active

Conversation

@da-phil
Copy link
Copy Markdown
Contributor

@da-phil da-phil commented Mar 30, 2026

  • Compute x_scale/y_scale locally in process() from actual roi_in/roi_out instead of using d->x_scale/d->y_scale which can be overwritten by precalculate_scale() called from distort_transform/distort_backtransform with different ROI dimensions, causing out-of-bounds interpolation access.

  • Implement distort_mask() enabling masks to work correctly when module is at non-standard pipeline position.

  • Fix buffer overflow in (ashift.c) g->buf allocation: the buffer was allocated using piece->buf_in.width * piece->buf_in.height but then filled with roi_in->width * roi_in->height * 4 floats. When roi_in->scale > 1.0 (zoomed in), roi_in dimensions exceed buf_in, causing a write past the end of the buffer. Fixed in both the CPU path (process()) and OpenCL path (process_cl()) by changing requested_size, g->buf_width, and g->buf_height to use roi_in dimensions instead of piece->buf_in.

Fixes #17286

Disclaimer: co-created with Claude.

* Compute x_scale/y_scale locally in process() from actual roi_in/roi_out
  instead of using d->x_scale/d->y_scale which can be overwritten by
  precalculate_scale() called from distort_transform/distort_backtransform
  with different ROI dimensions, causing out-of-bounds interpolation access.

* Implement distort_mask() enabling masks to work correctly when module
  is at non-standard pipeline position.

* Fix buffer overflow in (ashift.c) g->buf allocation:
  the buffer was allocated using piece->buf_in.width * piece->buf_in.height
  but then filled with roi_in->width * roi_in->height * 4 floats.
  When roi_in->scale > 1.0 (zoomed in), roi_in dimensions exceed buf_in,
  causing a ~6.6 MB write past the end of the buffer.
  Fixed in both the CPU path (process()) and OpenCL path (process_cl())
  by changing requested_size, g->buf_width, and g->buf_height to use
  roi_in dimensions instead of piece->buf_in.
@da-phil da-phil marked this pull request as ready for review March 30, 2026 21:51
@da-phil
Copy link
Copy Markdown
Contributor Author

da-phil commented Mar 30, 2026

I did some intensive testing and could not reproduce the crash mentioned in #17286.

@ralfbrown ralfbrown added bugfix pull request fixing a bug scope: image processing correcting pixels labels Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix pull request fixing a bug scope: image processing correcting pixels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when "scale pixels" module is moved on top of pixelpipe and "rotate and perspective" is used

2 participants