PR #26012 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26012 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26012.patch
>From 9a86a883f60bc002db2b077dc65093737ed53ce5 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Thu, 12 Nov 2026 22:59:05 +0100 Subject: [PATCH 1/6] avfilter/scale_eval: factor the evaluation of a dimension out No functional change. --- libavfilter/scale_eval.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c index 62e4e2de54a..1778136bc2a 100644 --- a/libavfilter/scale_eval.c +++ b/libavfilter/scale_eval.c @@ -55,6 +55,21 @@ enum var_name { VARS_NB }; +static int eval_dimension(void *log_ctx, const char *expr, const double *var_values, + int in_dimension, int *out_dimension) +{ + double res; + int ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, log_ctx); + if (ret < 0) + return ret; + if (!(res >= INT32_MIN && res <= INT32_MAX)) + return AVERROR(EINVAL); + + *out_dimension = (int) res == 0 ? in_dimension : (int) res; + return 0; +} + int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, @@ -86,26 +101,13 @@ int ff_scale_eval_dimensions(void *log_ctx, NULL, NULL, NULL, NULL, NULL, 0, log_ctx); var_values[VAR_OUT_W] = var_values[VAR_OW] = res == 0 ? inlink->w : trunc(res); - if ((ret = av_expr_parse_and_eval(&res, (expr = h_expr), - var_names, var_values, - NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0) + if ((ret = eval_dimension(log_ctx, (expr = h_expr), var_values, inlink->h, &eval_h)) < 0) goto fail; - if (!(res >= INT32_MIN && res <= INT32_MAX)) { - ret = AVERROR(EINVAL); - goto fail; - } - eval_h = var_values[VAR_OUT_H] = var_values[VAR_OH] = (int) res == 0 ? inlink->h : (int) res; + var_values[VAR_OUT_H] = var_values[VAR_OH] = eval_h; /* evaluate again the width, as it may depend on the output height */ - if ((ret = av_expr_parse_and_eval(&res, (expr = w_expr), - var_names, var_values, - NULL, NULL, NULL, NULL, NULL, 0, log_ctx)) < 0) + if ((ret = eval_dimension(log_ctx, (expr = w_expr), var_values, inlink->w, &eval_w)) < 0) goto fail; - if (!(res >= INT32_MIN && res <= INT32_MAX)) { - ret = AVERROR(EINVAL); - goto fail; - } - eval_w = (int) res == 0 ? inlink->w : (int) res; *ret_w = eval_w; *ret_h = eval_h; -- 2.54.0 >From 6e6504c680559752b42d92fbc4c0432f20df2628 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Thu, 12 Nov 2026 22:59:16 +0100 Subject: [PATCH 2/6] avfilter/scale_eval: restore the output width used for evaluating the height Since 805931dfc8 the first evaluation of the width set ow to the truncated expression result instead of the input width when it is truncated to 0. Found during triage of the security report nw59dSqw4SNa --- libavfilter/scale_eval.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c index 1778136bc2a..6d5bdf69ba0 100644 --- a/libavfilter/scale_eval.c +++ b/libavfilter/scale_eval.c @@ -80,7 +80,7 @@ int ff_scale_eval_dimensions(void *log_ctx, const char *expr; int eval_w, eval_h; int ret; - double var_values[VARS_NB], res; + double var_values[VARS_NB]; var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; @@ -96,10 +96,8 @@ int ff_scale_eval_dimensions(void *log_ctx, var_values[VAR_OVSUB] = 1 << out_desc->log2_chroma_h; /* evaluate width and height */ - av_expr_parse_and_eval(&res, (expr = w_expr), - var_names, var_values, - NULL, NULL, NULL, NULL, NULL, 0, log_ctx); - var_values[VAR_OUT_W] = var_values[VAR_OW] = res == 0 ? inlink->w : trunc(res); + if (eval_dimension(log_ctx, w_expr, var_values, inlink->w, &eval_w) >= 0) + var_values[VAR_OUT_W] = var_values[VAR_OW] = eval_w; if ((ret = eval_dimension(log_ctx, (expr = h_expr), var_values, inlink->h, &eval_h)) < 0) goto fail; -- 2.54.0 >From 0cd7103b526ab615c90e7b4e502e703aa938b3a6 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 13 Nov 2026 01:57:56 +0100 Subject: [PATCH 3/6] avfilter/aeval: limit the channel index of val() as unsigned Fixes: heap-buffer-overflow (read) Found during triage of the security report nw59dSqw4SNa Out of array read Replicated through UnModified FFmpeg with ASAN --- libavfilter/aeval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/aeval.c b/libavfilter/aeval.c index baea5886fcf..e88cb331ff1 100644 --- a/libavfilter/aeval.c +++ b/libavfilter/aeval.c @@ -77,7 +77,7 @@ typedef struct EvalContext { static double val(void *priv, double ch) { EvalContext *eval = priv; - return eval->channel_values[FFMIN((int)ch, eval->nb_in_channels-1)]; + return eval->channel_values[FFMIN((unsigned)(int)ch, eval->nb_in_channels-1)]; } static double (* const aeval_func1[])(void *, double) = { val, NULL }; -- 2.54.0 >From 36f424370b1aa855415f860c68e616ffdbc9f743 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 13 Nov 2026 02:07:25 +0100 Subject: [PATCH 4/6] avfilter/f_select: do not round the result to float Fixes: heap-buffer-overflow (read) Found during triage of the security report nw59dSqw4SNa Out of array read Replicated through UnModified FFmpeg with ASAN --- libavfilter/f_select.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c index c1c93fd9732..2f11cadb750 100644 --- a/libavfilter/f_select.c +++ b/libavfilter/f_select.c @@ -407,7 +407,8 @@ static void select_frame(AVFilterContext *ctx, AVFrame *frame) } else if (isnan(res) || res < 0) { select->select_out = 0; /* first output */ } else { - select->select_out = FFMIN(ceilf(res)-1, select->nb_outputs-1); /* other outputs */ + unsigned u = ceil(res); + select->select_out = FFMIN(u-1, select->nb_outputs-1); /* other outputs */ } av_log(inlink->dst, AV_LOG_DEBUG, " -> select:%f select_out:%d\n", res, select->select_out); -- 2.54.0 >From e4508cbad74b0cd2668bab8f828dd45a44e55800 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 13 Nov 2026 01:58:08 +0100 Subject: [PATCH 5/6] avfilter/vf_fftfilt: mask the coordinates of weight_Y/U/V() Fixes: heap-buffer-overflow (read) Found during triage of the security report nw59dSqw4SNa Out of array read Replicated through UnModified FFmpeg with ASAN --- libavfilter/vf_fftfilt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavfilter/vf_fftfilt.c b/libavfilter/vf_fftfilt.c index 043479b0c3f..4b0851dad65 100644 --- a/libavfilter/vf_fftfilt.c +++ b/libavfilter/vf_fftfilt.c @@ -107,7 +107,8 @@ AVFILTER_DEFINE_CLASS(fftfilt); static inline double lum(void *priv, double x, double y, int plane) { FFTFILTContext *s = priv; - return s->rdft_vdata_out[plane][(int)x * s->rdft_vstride[plane] + (int)y]; + return s->rdft_vdata_out[plane][((int)x & (s->rdft_hlen[plane] - 1)) * s->rdft_vstride[plane] + + ((int)y & (s->rdft_vlen[plane] - 1))]; } static double weight_Y(void *priv, double x, double y) { return lum(priv, x, y, Y); } -- 2.54.0 >From 1280f982c55e5b96532b7c02739fc11e929f5567 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Sun, 8 Nov 2026 16:40:46 +0100 Subject: [PATCH 6/6] avfilter/vf_showinfo: do not assume terminated detection bbox strings Found during triage of the security report jBRKMspuGY2H --- libavfilter/vf_showinfo.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index ecd3459e0de..66984be0afb 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -169,17 +169,19 @@ static void dump_detection_bbox(AVFilterContext *ctx, const AVFrameSideData *sd) header = (const AVDetectionBBoxHeader *)sd->data; nb_bboxes = header->nb_bboxes; - av_log(ctx, AV_LOG_INFO, "source: %s\n", header->source); + av_log(ctx, AV_LOG_INFO, "source: %.*s\n", (int)sizeof(header->source), header->source); for (int i = 0; i < nb_bboxes; i++) { bbox = av_get_detection_bbox(header, i); - av_log(ctx, AV_LOG_INFO, "index: %d,\tregion: (%d, %d) -> (%d, %d), label: %s, confidence: %d/%d.\n", + av_log(ctx, AV_LOG_INFO, "index: %d,\tregion: (%d, %d) -> (%d, %d), label: %.*s, confidence: %d/%d.\n", i, bbox->x, bbox->y, bbox->x + bbox->w, bbox->y + bbox->h, - bbox->detect_label, bbox->detect_confidence.num, bbox->detect_confidence.den); + (int)sizeof(bbox->detect_label), bbox->detect_label, + bbox->detect_confidence.num, bbox->detect_confidence.den); if (bbox->classify_count > 0) { for (int j = 0; j < bbox->classify_count; j++) { - av_log(ctx, AV_LOG_INFO, "\t\tclassify: label: %s, confidence: %d/%d.\n", - bbox->classify_labels[j], bbox->classify_confidences[j].num, bbox->classify_confidences[j].den); + av_log(ctx, AV_LOG_INFO, "\t\tclassify: label: %.*s, confidence: %d/%d.\n", + (int)sizeof(bbox->classify_labels[j]), bbox->classify_labels[j], + bbox->classify_confidences[j].num, bbox->classify_confidences[j].den); } } } -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
