From a45fe72c9d88aeed10fa3a665c7243f351a1035d Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Thu, 23 Apr 2026 11:27:20 +0800 Subject: [PATCH] avfilter/scale_eval: reject non-positive output dimensions When scale filter expressions evaluate to zero or negative output dimensions (e.g. cascaded scale=...:-2 on extreme aspect ratios), ff_scale_adjust_dimensions() only checked for int32 overflow and passed them through, potentially hanging downstream components. Reject them explicitly so the pipeline fails fast. Callers that currently ignore the return value will be updated in the following patches to propagate the error. Signed-off-by: Jun Zhao --- libavfilter/scale_eval.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c index 34365c0b3b..62e4e2de54 100644 --- a/libavfilter/scale_eval.c +++ b/libavfilter/scale_eval.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include "scale_eval.h" #include "libavutil/eval.h" @@ -186,6 +187,13 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, if ((int32_t)w != w || (int32_t)h != h) return AVERROR(EINVAL); + if (w <= 0 || h <= 0) { + av_log(inlink->dst, AV_LOG_ERROR, + "Rescaled dimensions %"PRId64"x%"PRId64" are invalid, " + "output dimensions must be positive.\n", w, h); + return AVERROR(EINVAL); + } + *ret_w = w; *ret_h = h;