* [FFmpeg-devel] [PR] avfilter/vf_stack: add checks for the final canvas dimensions (PR #21369)
@ 2026-01-04 0:32 James Almer via ffmpeg-devel
0 siblings, 0 replies; only message in thread
From: James Almer via ffmpeg-devel @ 2026-01-04 0:32 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: James Almer
PR #21369 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21369
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21369.patch
Prevents potential integer overflows when trying to stitch absurdly huge images together.
Fixes #YWH-PGM40646-38.
>From 4fad1367040e093c8a52f4f34054e4feb5203243 Mon Sep 17 00:00:00 2001
From: James Almer <jamrial@gmail.com>
Date: Sat, 3 Jan 2026 21:31:30 -0300
Subject: [PATCH] avfilter/vf_stack: add checks for the final canvas dimensions
Prevents potential integer overflows when trying to stitch absurdly huge images together.
Fixes #YWH-PGM40646-38.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavfilter/vf_stack.c | 38 ++++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c
index a36e1bab64..6e9ac60a56 100644
--- a/libavfilter/vf_stack.c
+++ b/libavfilter/vf_stack.c
@@ -234,6 +234,8 @@ static int config_output(AVFilterLink *outlink)
item->y[1] = item->y[2] = AV_CEIL_RSHIFT(height, s->desc->log2_chroma_h);
item->y[0] = item->y[3] = height;
+ if (height > INT_MAX - ctx->inputs[i]->h)
+ return AVERROR(EINVAL);
height += ctx->inputs[i]->h;
}
}
@@ -259,6 +261,8 @@ static int config_output(AVFilterLink *outlink)
return ret;
}
+ if (width > INT_MAX - ctx->inputs[i]->w)
+ return AVERROR(EINVAL);
width += ctx->inputs[i]->w;
}
}
@@ -294,8 +298,13 @@ static int config_output(AVFilterLink *outlink)
item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, s->desc->log2_chroma_h);
item->y[0] = item->y[3] = inh;
+
+ if (inw > INT_MAX - ctx->inputs[k]->w)
+ return AVERROR(EINVAL);
inw += ctx->inputs[k]->w;
}
+ if (height > INT_MAX - row_height)
+ return AVERROR(EINVAL);
height += row_height;
if (!i)
width = inw;
@@ -351,26 +360,41 @@ static int config_output(AVFilterLink *outlink)
if (size == i || size < 0 || size >= s->nb_inputs)
return AVERROR(EINVAL);
- if (!j)
+ if (!j) {
+ if (inw > INT_MAX - ctx->inputs[size]->w)
+ return AVERROR(EINVAL);
inw += ctx->inputs[size]->w;
- else
+ } else {
+ if (inh > INT_MAX - ctx->inputs[size]->w)
+ return AVERROR(EINVAL);
inh += ctx->inputs[size]->w;
+ }
} else if (sscanf(arg3, "h%d", &size) == 1) {
if (size == i || size < 0 || size >= s->nb_inputs)
return AVERROR(EINVAL);
- if (!j)
+ if (!j) {
+ if (inw > INT_MAX - ctx->inputs[size]->h)
+ return AVERROR(EINVAL);
inw += ctx->inputs[size]->h;
- else
+ } else {
+ if (inh > INT_MAX - ctx->inputs[size]->h)
+ return AVERROR(EINVAL);
inh += ctx->inputs[size]->h;
+ }
} else if (sscanf(arg3, "%d", &size) == 1) {
if (size < 0)
return AVERROR(EINVAL);
- if (!j)
+ if (!j) {
+ if (inw > INT_MAX - size)
+ return AVERROR(EINVAL);
inw += size;
- else
+ } else {
+ if (inh > INT_MAX - size)
+ return AVERROR(EINVAL);
inh += size;
+ }
} else {
return AVERROR(EINVAL);
}
@@ -384,6 +408,8 @@ static int config_output(AVFilterLink *outlink)
item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, s->desc->log2_chroma_h);
item->y[0] = item->y[3] = inh;
+ if (inlink->w > INT_MAX - inw || inlink->h > INT_MAX - inh)
+ return AVERROR(EINVAL);
width = FFMAX(width, inlink->w + inw);
height = FFMAX(height, inlink->h + inh);
}
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-01-04 0:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-04 0:32 [FFmpeg-devel] [PR] avfilter/vf_stack: add checks for the final canvas dimensions (PR #21369) James Almer via ffmpeg-devel
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