PR #22852 opened by Jun Zhao (mypopydev) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22852 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22852.patch
>From b15be391619edc7aab23a9129fd9419936aa9cff Mon Sep 17 00:00:00 2001 From: Jun Zhao <[email protected]> Date: Sat, 18 Apr 2026 11:37:25 +0800 Subject: [PATCH 1/2] 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. Signed-off-by: Jun Zhao <[email protected]> --- libavfilter/scale_eval.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c index 34365c0b3b6..62e4e2de54a 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 <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; -- 2.52.0 >From 05422d4fce4b8e8a2c032abafb29468acca05493 Mon Sep 17 00:00:00 2001 From: Jun Zhao <[email protected]> Date: Sat, 18 Apr 2026 11:37:34 +0800 Subject: [PATCH 2/2] avcodec/libsvtav1: reject tiny inputs and avoid drain-time hang Two defensive fixes for the hang reported in issue #22817: 1. Reject inputs smaller than 64x64 in config_enc_params(); SVT-AV1 may otherwise silently accept them without producing output. 2. In eb_receive_packet(), when EB_NoErrorEmptyQueue is returned after EOS has been signalled (eos_flag == EOS_SENT), return AVERROR_EOF instead of AVERROR(EAGAIN) so the caller does not loop forever. Fix #22817 Signed-off-by: Jun Zhao <[email protected]> --- libavcodec/libsvtav1.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index fec2ed596ea..450bb5da2ad 100644 --- a/libavcodec/libsvtav1.c +++ b/libavcodec/libsvtav1.c @@ -215,6 +215,17 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, const AVPixFmtDescriptor *desc; av_unused const AVDictionaryEntry *en = NULL; + // SVT-AV1 requires input dimensions of at least 64x64. Reject smaller + // inputs explicitly here to produce a clear error rather than relying on + // the library's internal validation, which may silently fail to produce + // output and cause the caller to hang. + if (avctx->width < 64 || avctx->height < 64) { + av_log(avctx, AV_LOG_ERROR, + "Input dimensions %dx%d are smaller than the minimum 64x64 " + "supported by SVT-AV1.\n", avctx->width, avctx->height); + return AVERROR(EINVAL); + } + // Update param from options if (svt_enc->enc_mode >= -1) param->enc_mode = svt_enc->enc_mode; @@ -651,9 +662,17 @@ static int eb_receive_packet(AVCodecContext *avctx, AVPacket *pkt) av_frame_unref(svt_enc->frame); svt_ret = svt_av1_enc_get_packet(svt_enc->svt_handle, &headerPtr, svt_enc->eos_flag); - if (svt_ret == EB_NoErrorEmptyQueue) + if (svt_ret == EB_NoErrorEmptyQueue) { + // If we have already signalled end-of-stream to the encoder but it + // produces no output (e.g. when the encoder was fed insufficient or + // invalid input), returning EAGAIN would cause the caller to loop + // forever. Return EOF instead to let the pipeline terminate. + if (svt_enc->eos_flag == EOS_SENT) { + svt_enc->eos_flag = EOS_RECEIVED; + return AVERROR_EOF; + } return AVERROR(EAGAIN); - else if (svt_ret != EB_ErrorNone) + } else if (svt_ret != EB_ErrorNone) return svt_print_error(avctx, svt_ret, "Error getting an output packet from encoder"); #if SVT_AV1_CHECK_VERSION(2, 0, 0) -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
