Commit c61944093f for ffmpeg
commit c61944093f57dccb9079bad1612418b2ccb3f6c1
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Sun Oct 11 07:31:13 2026 +0200
swscale: reject interlaced frames whose fields have no lines
A one line interlaced frame has an empty bottom field, when source and
destination format were equal the graph was still built for it and
divided by the zero slice height.
Fixes: division by zero
Fixes: 9FwqJRpgNJo3
Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24851
Division by zero Replicated through UnModified FFmpeg with UBSAN
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index d224c3275b..070b0f5939 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -1562,6 +1562,12 @@ int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, const AVFrame *src)
goto fail;
}
+ if (src_fmt.height <= 0 || dst_fmt.height <= 0) {
+ err_msg = "Interlaced frames need at least two lines";
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
src_ok = ff_test_fmt(backends, &src_fmt, 0);
dst_ok = ff_test_fmt(backends, &dst_fmt, 1);
if ((!src_ok || !dst_ok) && !ff_fmt_equal(&src_fmt, &dst_fmt)) {