From 2417c498e110ccbe14d71bac569e8cdbfe7e3ea3 Mon Sep 17 00:00:00 2001 From: Andrii Ryzhkov Date: Mon, 6 Jul 2026 22:04:56 +0200 Subject: [PATCH] Fix raw denoise crash on raws with tight CFA border --- src/common/ai/restore_raw_bayer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common/ai/restore_raw_bayer.c b/src/common/ai/restore_raw_bayer.c index 2c46112d351d..05a5f192f7f3 100644 --- a/src/common/ai/restore_raw_bayer.c +++ b/src/common/ai/restore_raw_bayer.c @@ -597,11 +597,16 @@ int dt_restore_raw_bayer(dt_restore_context_t *ctx, } } - // extended extent = core ± seam where a neighbor exists; matches model-output validity - const int ext_y0 = has_top ? sensor_py_base - sensor_O : sensor_py_base; - const int ext_y1 = has_bot ? sensor_py_end + sensor_O : sensor_py_end; - const int ext_x0 = has_left ? sensor_px_base - sensor_O : sensor_px_base; - const int ext_x1 = has_right? sensor_px_end + sensor_O : sensor_px_end; + // extended extent = core ± seam where a neighbor exists; matches + // model-output validity; clamped to the CFA buffer bounds + const int ext_y0 = MAX(0, + has_top? sensor_py_base - sensor_O : sensor_py_base); + const int ext_y1 = MIN(height, + has_bot ? sensor_py_end + sensor_O : sensor_py_end); + const int ext_x0 = MAX(0, + has_left ? sensor_px_base - sensor_O : sensor_px_base); + const int ext_x1 = MIN(width, + has_right? sensor_px_end + sensor_O : sensor_px_end); for(int sr = ext_y0; sr < ext_y1; sr++) {