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 <barryjzhao@tencent.com>
This commit is contained in:
Jun Zhao 2026-04-23 11:27:20 +08:00 committed by Jun Zhao
parent c55ab93eef
commit a45fe72c9d

View file

@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <inttypes.h>
#include <stdint.h>
#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;