PR #25162 opened by Forgejo_Fairy URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25162 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25162.patch
Fixes #24459. Scaling 6×4096 RGBA to 8192×64 YUV420P with `fast_bilinear` falls back to bilinear and reaches the vertical chroma filter-size limit. The internal cascade rejects the conversion because horizontal enlargement makes the total-area reduction insufficient for its guard. Check the dimensions independently, permitting cascading when either source dimension exceeds twice its destination dimension. This preserves a bound on recursive cascading and allows the reported conversion to produce a frame. Add generated-input FATE tests for vertical and horizontal reductions combined with enlargement of the other axis. Both tests fail before the fix and pass afterward on arm64 and x86-64, with SIMD enabled and disabled. Six related scaler FATE tests also pass on both architectures. The original reproducer and both new tests pass under Clang ASan/UBSan on arm64 with leak detection enabled. The reported fast-bilinear case starts failing at 1edf129cbc89, which introduces the narrow-width fallback: a scalar API test produces 64 rows at parent 9434ec5f767c and fails initialization at that commit. The fix retains this fallback. From 4b92d0e0ae4ddef9c8dcdf5156d3c7b48598e997 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Sat, 17 Oct 2026 13:28:10 +0000 Subject: [PATCH] swscale/utils: allow cascades for opposite-direction resizing The cascade guard compares the total image areas, so enlarging one axis can prevent a cascade needed for a large reduction on the other. For example, 6x4096 RGBA to 8192x64 YUV420P with fast_bilinear falls back to bilinear and reaches the vertical chroma filter size limit, but the area check rejects the conversion. Require a reduction by more than two in at least one dimension instead. This preserves a bound on recursive cascading without letting enlargement on the other axis cancel the reduction. Add generated-input FATE coverage for vertical and horizontal reductions combined with enlargement of the other axis. Fixes: #24459 Assisted-by: Fairy --- libswscale/utils.c | 4 +++- tests/fate/filter-video.mak | 4 ++++ tests/ref/fate/filter-scale-cascade-horizontal | 6 ++++++ tests/ref/fate/filter-scale-cascade-vertical | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/ref/fate/filter-scale-cascade-horizontal create mode 100644 tests/ref/fate/filter-scale-cascade-vertical diff --git a/libswscale/utils.c b/libswscale/utils.c index 138c1a4edd..08fb5dc9e2 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1855,7 +1855,9 @@ fail: // FIXME replace things by appropriate error codes if (isALPHA(srcFormat)) tmpFormat = AV_PIX_FMT_YUVA420P; - if (srcW*(int64_t)srcH <= 4LL*dstW*dstH) + /* A large reduction in either dimension can require a cascade, even + * when upscaling the other dimension increases the total area. */ + if (srcW <= 2LL * dstW && srcH <= 2LL * dstH) return AVERROR(EINVAL); ret = av_image_alloc(c->cascaded_tmp[0], c->cascaded_tmpStride[0], diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 4a065ec032..fd75fafe87 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -181,6 +181,10 @@ FATE_FILTER-$(call FILTERFRAMECRC, TESTSRC FORMAT CONCAT SCALE, LAVFI_INDEV FILE fate-filter-lavd-scalenorm: tests/data/filtergraphs/scalenorm fate-filter-lavd-scalenorm: CMD = framecrc -f lavfi -graph_file $(TARGET_PATH)/tests/data/filtergraphs/scalenorm -i dummy +FATE_FILTER-$(call FILTERFRAMECRC, TESTSRC FORMAT SCALE, SWSCALE_ALPHA) += fate-filter-scale-cascade-vertical fate-filter-scale-cascade-horizontal +fate-filter-scale-cascade-vertical: CMD = framecrc -flags bitexact -lavfi testsrc=s=6x4096:r=1:d=1,scale=flags=accurate_rnd+bitexact,format=rgba,scale=8192:64:flags=fast_bilinear+accurate_rnd+bitexact,format=yuv420p -frames:v 1 +fate-filter-scale-cascade-horizontal: CMD = framecrc -flags bitexact -lavfi testsrc=s=8192x6:r=1:d=1,scale=flags=accurate_rnd+bitexact,format=rgba,scale=64:8192:flags=bilinear+accurate_rnd+bitexact,format=yuv420p -frames:v 1 + FATE_FILTER-$(call FILTERFRAMECRC, COLOR FORMAT SCALE CROP) += fate-filter-scale-fast-bilinear-wide-edge fate-filter-scale-fast-bilinear-wide-edge: CMD = framecrc -flags bitexact -lavfi color=c=red:s=40000x1:r=1:d=1,format=yuv444p,scale=40032:1:flags=fast_bilinear,crop=1:1:40031:0 -frames:v 1 diff --git a/tests/ref/fate/filter-scale-cascade-horizontal b/tests/ref/fate/filter-scale-cascade-horizontal new file mode 100644 index 0000000000..7e21a1d25a --- /dev/null +++ b/tests/ref/fate/filter-scale-cascade-horizontal @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 64x8192 +#sar 0: 0/1 +0, 0, 0, 1, 786432, 0xa096c808 diff --git a/tests/ref/fate/filter-scale-cascade-vertical b/tests/ref/fate/filter-scale-cascade-vertical new file mode 100644 index 0000000000..43888f0c72 --- /dev/null +++ b/tests/ref/fate/filter-scale-cascade-vertical @@ -0,0 +1,6 @@ +#tb 0: 1/1 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 8192x64 +#sar 0: 0/1 +0, 0, 0, 1, 786432, 0x1f0be0ab -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
