Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 02/22] avformat/bintext: Check avio_size() return
Date: Fri, 12 Jul 2024 01:33:56 +0200
Message-ID: <20240711233417.1896879-2-michael@niedermayer.cc> (raw)
In-Reply-To: <20240711233417.1896879-1-michael@niedermayer.cc>

Fixes: CID1604503 Overflowed constant
Fixes: CID1604566 Overflowed constant

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/bintext.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/libavformat/bintext.c b/libavformat/bintext.c
index 90d48b66914..c96c14ccd9d 100644
--- a/libavformat/bintext.c
+++ b/libavformat/bintext.c
@@ -93,9 +93,12 @@ static int next_tag_read(AVFormatContext *avctx, uint64_t *fsize)
     AVIOContext *pb = avctx->pb;
     char buf[36];
     int len;
-    uint64_t start_pos = avio_size(pb) - 256;
+    int64_t start_pos = avio_size(pb);
 
-    avio_seek(pb, start_pos, SEEK_SET);
+    if (start_pos < 256)
+        return AVERROR_INVALIDDATA;
+
+    avio_seek(pb, start_pos - 256, SEEK_SET);
     if (avio_read(pb, buf, sizeof(next_magic)) != sizeof(next_magic))
         return -1;
     if (memcmp(buf, next_magic, sizeof(next_magic)))
@@ -245,7 +248,10 @@ static int xbin_read_header(AVFormatContext *s)
         return AVERROR(EIO);
 
     if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
-        bin->fsize = avio_size(pb) - 9 - st->codecpar->extradata_size;
+        int64_t fsize =  avio_size(pb);
+        if (fsize < 9 + st->codecpar->extradata_size)
+            return 0;
+        bin->fsize = fsize - 9 - st->codecpar->extradata_size;
         ff_sauce_read(s, &bin->fsize, NULL, 0);
         avio_seek(pb, 9 + st->codecpar->extradata_size, SEEK_SET);
     }
@@ -285,7 +291,10 @@ static int adf_read_header(AVFormatContext *s)
 
     if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
         int got_width = 0;
-        bin->fsize = avio_size(pb) - 1 - 192 - 4096;
+        int64_t fsize =  avio_size(pb);
+        if (fsize < 1 + 192 + 4096)
+            return 0;
+        bin->fsize = fsize - 1 - 192 - 4096;
         st->codecpar->width = 80<<3;
         ff_sauce_read(s, &bin->fsize, &got_width, 0);
         if (st->codecpar->width < 8)
@@ -318,6 +327,7 @@ static int idf_read_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     AVStream *st;
     int got_width = 0, ret;
+    int64_t fsize;
 
     if (!(pb->seekable & AVIO_SEEKABLE_NORMAL))
         return AVERROR(EIO);
@@ -332,14 +342,18 @@ static int idf_read_header(AVFormatContext *s)
     st->codecpar->extradata[0] = 16;
     st->codecpar->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT;
 
-    avio_seek(pb, avio_size(pb) - 4096 - 48, SEEK_SET);
+    fsize = avio_size(pb);
+    if (fsize < 12 + 4096 + 48)
+        return AVERROR_INVALIDDATA;
+    bin->fsize = fsize - 12 - 4096 - 48;
+
+    avio_seek(pb, bin->fsize + 12, SEEK_SET);
 
     if (avio_read(pb, st->codecpar->extradata + 2 + 48, 4096) < 0)
         return AVERROR(EIO);
     if (avio_read(pb, st->codecpar->extradata + 2, 48) < 0)
         return AVERROR(EIO);
 
-    bin->fsize = avio_size(pb) - 12 - 4096 - 48;
     ff_sauce_read(s, &bin->fsize, &got_width, 0);
     if (st->codecpar->width < 8)
         return AVERROR_INVALIDDATA;
-- 
2.45.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2024-07-11 23:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-11 23:33 [FFmpeg-devel] [PATCH 01/22] avformat/asfdec_o: Check size of index object Michael Niedermayer
2024-07-11 23:33 ` Michael Niedermayer [this message]
2024-07-11 23:33 ` [FFmpeg-devel] [PATCH 03/22] avformat/hlsenc: Check ret Michael Niedermayer
2024-07-11 23:33 ` [FFmpeg-devel] [PATCH 04/22] avformat/hnm: Check *chunk_size Michael Niedermayer
2024-07-11 23:33 ` [FFmpeg-devel] [PATCH 05/22] avformat/matroskadec: Use int64_t size Michael Niedermayer
2024-07-12  8:42   ` Andreas Rheinhardt
2024-07-12 14:59     ` Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 06/22] avformat/mm: Check length Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 07/22] avformat/mov: Use 64bit for str_size Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 08/22] avformat/mp3dec; Check for avio_size() failure Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 09/22] avformat/mp3dec: Check header_filesize Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 10/22] avformat/nsvdec: Check asize for PCM Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 11/22] avformat/sapdec: Check ffurl_get_file_handle() for error Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 12/22] avformat/sauce: Check avio_size() for failure Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 13/22] avformat/siff: Basic pkt_size check Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 14/22] avformat/tty: Check avio_size() Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 15/22] avformat/ty: rec_size seems to only need 32bit Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 16/22] avformat/webpenc: Check filesize in trailer Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 17/22] avformat/xmv: Check this_packet_size Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 18/22] avutil/avsscanf: Remove dead code Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 19/22] avutil/buffer: Check ff_mutex_init() for failure Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 20/22] avutil/frame: Check log2_crop_align Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 21/22] avutil/slicethread: Check pthread_*_init() for failure Michael Niedermayer
2024-07-11 23:34 ` [FFmpeg-devel] [PATCH 22/22] avfilter/vf_xfade: Check ff_inlink_consume_frame() " Michael Niedermayer
2024-07-21 14:43 ` [FFmpeg-devel] [PATCH 01/22] avformat/asfdec_o: Check size of index object Michael Niedermayer

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=20240711233417.1896879-2-michael@niedermayer.cc \
    --to=michael@niedermayer.cc \
    --cc=ffmpeg-devel@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