From: Alex Teaca via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Alex Teaca <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] swscale/utils: sanity check scaling increments (PR #22305)
Date: Fri, 27 Feb 2026 09:49:39 -0000
Message-ID: <177218577994.25.11583710475883257861@29965ddac10e> (raw)
PR #22305 opened by Alex Teaca (alex-teaca)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22305
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22305.patch
Large frame sizes produce scaling increments that overflow when stored
in the c->lumXInc and c->lumYInc int variables.
The calculation is performed in int64_t but truncated to int.
Later, the incorrect values are passed to initFilter which applies
arithmetic operations that produce undefined-behavior.
This patch rejects frame sizes where the scaling increments
don't fit into int (c->lumXInc and c->lumYInc).
Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/21588
Signed-off-by: Alex Teaca <ionutalex.teaca@gmail.com>
>From 72ca1460b24eed0b043115d89a1ae24cda1fbcfa Mon Sep 17 00:00:00 2001
From: Alex Teaca <ionutalex.teaca@gmail.com>
Date: Fri, 27 Feb 2026 11:01:33 +0200
Subject: [PATCH] swscale/utils: sanity check scaling increments
Large frame sizes produce scaling increments that overflow when stored
in the c->lumXInc and c->lumYInc int variables.
The calculation is performed in int64_t but truncated to int.
Later, the incorrect values are passed to initFilter which applies
arithmetic operations that produce undefined-behavior.
This patch rejects frame sizes where the scaling increments
don't fit into int (c->lumXInc and c->lumYInc).
Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/21588
Signed-off-by: Alex Teaca <ionutalex.teaca@gmail.com>
---
libswscale/utils.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 52095ab2c7..ced51c6147 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -1128,6 +1128,7 @@ av_cold int ff_sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter,
int dstH = sws->dst_h;
int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 66, 16);
int flags, cpu_flags;
+ int64_t tmpLumXInc, tmpLumYInc;
enum AVPixelFormat srcFormat, dstFormat;
const AVPixFmtDescriptor *desc_src;
const AVPixFmtDescriptor *desc_dst;
@@ -1219,8 +1220,18 @@ av_cold int ff_sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter,
if (!srcFilter)
srcFilter = &dummyFilter;
- c->lumXInc = (((int64_t)srcW << 16) + (dstW >> 1)) / dstW;
- c->lumYInc = (((int64_t)srcH << 16) + (dstH >> 1)) / dstH;
+ tmpLumXInc = (((int64_t)srcW << 16) + (dstW >> 1)) / dstW;
+ tmpLumYInc = (((int64_t)srcH << 16) + (dstH >> 1)) / dstH;
+
+ if (tmpLumXInc > INT_MAX || tmpLumYInc > INT_MAX) {
+ av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d makes invalid scaling increments\n",
+ srcW, srcH, dstW, dstH);
+ return AVERROR(EINVAL);
+ }
+
+ c->lumXInc = tmpLumXInc;
+ c->lumYInc = tmpLumYInc;
+
c->dstFormatBpp = av_get_bits_per_pixel(desc_dst);
c->srcFormatBpp = av_get_bits_per_pixel(desc_src);
c->vRounder = 4 * 0x0001000100010001ULL;
--
2.52.0
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2026-02-27 9:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=177218577994.25.11583710475883257861@29965ddac10e \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git