From: Timo Rothenpieler via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Timo Rothenpieler <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] avformat/img2dec: reject input images too big to fit into a single packet (PR #21334)
Date: Wed, 31 Dec 2025 02:55:49 -0000
Message-ID: <176714974978.25.975860886018665805@4457048688e7> (raw)
PR #21334 opened by Timo Rothenpieler (BtbN)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21334
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21334.patch
Not entirely sure if it should instead use some entirely different
approach here, given that images exceeding 2GB don't seem that crazy
to me, but so far processing such images results in a heap overflow,
since the size addition overflows and a much too small packet is
allocated and its size never checked again when writing into it.
Fixes #YWH-PGM40646-32
>From adebaa447e94078d17e44cefe3ade507d6c5b0f2 Mon Sep 17 00:00:00 2001
From: Timo Rothenpieler <timo@rothenpieler.org>
Date: Wed, 31 Dec 2025 03:41:21 +0100
Subject: [PATCH] avformat/img2dec: reject input images too big to fit into a
single packet
Not entirely sure if it should instead use some entirely different
approach here, given that images exceeding 2GB don't seem that crazy
to me, but so far processing such images results in a heap overflow,
since the size addition overflows and a much too small packet is
allocated and its size never checked again when writing into it.
Fixes #YWH-PGM40646-32
---
libavformat/img2dec.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 8f1c9013ca..9c2c519e4f 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -365,8 +365,10 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
VideoDemuxData *s = s1->priv_data;
AVBPrint filename;
int i, res;
- int size[3] = { 0 }, ret[3] = { 0 };
- AVIOContext *f[3] = { NULL };
+ int ret[3] = { 0 };
+ int64_t size[3] = { 0 };
+ int64_t total_size;
+ AVIOContext *f[3] = { NULL };
AVCodecParameters *par = s1->streams[0]->codecpar;
av_bprint_init(&filename, 0, AV_BPRINT_SIZE_UNLIMITED);
@@ -456,7 +458,11 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
}
}
- res = av_new_packet(pkt, size[0] + size[1] + size[2]);
+ total_size = size[0] + size[1] + size[2];
+ if (total_size < 0 || total_size > INT_MAX || size[0] > INT_MAX || size[1] > INT_MAX || size[2] > INT_MAX)
+ return AVERROR_INVALIDDATA;
+
+ res = av_new_packet(pkt, total_size);
if (res < 0) {
goto fail;
}
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-12-31 2:56 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=176714974978.25.975860886018665805@4457048688e7 \
--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