From patchwork Wed Sep 4 16:04:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 14901 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C92FB446EF2 for ; Wed, 4 Sep 2019 19:11:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AADDE687FE4; Wed, 4 Sep 2019 19:11:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe07-2.mx.upcmail.net (vie01a-dmta-pe07-2.mx.upcmail.net [84.116.36.18]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C0470687FC1 for ; Wed, 4 Sep 2019 19:11:18 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe07.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1i5XnH-0004Qv-37 for ffmpeg-devel@ffmpeg.org; Wed, 04 Sep 2019 18:06:03 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 5XmJiF6Lrwlys5XmJibUVB; Wed, 04 Sep 2019 18:05:03 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.41.20 X-CNFS-Analysis: v=2.3 cv=E5OzWpVl c=1 sm=1 tr=0 a=I1eytVlZLDX1BM2VTtTtSw==:117 a=I1eytVlZLDX1BM2VTtTtSw==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=GFjJLvbUEO9jNpYM-LIA:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 4 Sep 2019 18:04:58 +0200 Message-Id: <20190904160458.28245-5-michael@niedermayer.cc> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904160458.28245-1-michael@niedermayer.cc> References: <20190904160458.28245-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfPLSoIYbsmYRmfmDEyi8jCPOFcw51ImcXaTz5W307OdD0TzX7UrKMnBPbj61g1nkQb4p8BKcSYbxnKGHEwTcm3UZ8jGRgG69gUHKINTQl8EA4x7bnAtB MFZp7joOfoUVuZeR1WsWBquIMt8AK0UWtUGXPjKlFPsVkw1I7MzZxk8a Subject: [FFmpeg-devel] [PATCH 5/5] avformat/vividas: Test size and packet numbers a bit more X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Michael Niedermayer --- libavformat/vividas.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/libavformat/vividas.c b/libavformat/vividas.c index 7ccec85761..62d714dd2b 100644 --- a/libavformat/vividas.c +++ b/libavformat/vividas.c @@ -427,6 +427,7 @@ static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *bu int maxnp=0; AVIOContext *pb; int i; + int64_t filesize = avio_size(s->pb); pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL); if (!pb) @@ -435,11 +436,8 @@ static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *bu ffio_read_varlen(pb); // track_index_len avio_r8(pb); // 'c' viv->n_sb_blocks = ffio_read_varlen(pb); - if (viv->n_sb_blocks * 2 > size) { - viv->n_sb_blocks = 0; - av_free(pb); - return AVERROR_INVALIDDATA; - } + if (viv->n_sb_blocks * 2 > size) + goto error; viv->sb_blocks = av_calloc(viv->n_sb_blocks, sizeof(VIV_SB_block)); if (!viv->sb_blocks) { viv->n_sb_blocks = 0; @@ -451,24 +449,37 @@ static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *bu poff = 0; for (i = 0; i < viv->n_sb_blocks; i++) { + uint64_t size_tmp = ffio_read_varlen(pb); + uint64_t n_packets_tmp = ffio_read_varlen(pb); + + if (size_tmp > INT_MAX || n_packets_tmp > INT_MAX) + goto error; + viv->sb_blocks[i].byte_offset = off; viv->sb_blocks[i].packet_offset = poff; - viv->sb_blocks[i].size = ffio_read_varlen(pb); - viv->sb_blocks[i].n_packets = ffio_read_varlen(pb); + viv->sb_blocks[i].size = size_tmp; + viv->sb_blocks[i].n_packets = n_packets_tmp; off += viv->sb_blocks[i].size; poff += viv->sb_blocks[i].n_packets; - if (maxnp < viv->sb_blocks[i].n_packets) maxnp = viv->sb_blocks[i].n_packets; } + if (filesize > 0 && poff > filesize) + goto error; + viv->sb_entries = av_calloc(maxnp, sizeof(VIV_SB_entry)); av_free(pb); return 0; +error: + av_free(pb); + viv->n_sb_blocks = 0; + av_freep(&viv->sb_blocks); + return AVERROR_INVALIDDATA; } static void load_sb_block(AVFormatContext *s, VividasDemuxContext *viv, unsigned expected_size)