From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id A8C6340368 for ; Wed, 23 Mar 2022 20:57:45 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 656EB68B14F; Wed, 23 Mar 2022 22:57:42 +0200 (EET) Received: from vie01a-dmta-at01-3.mx.upcmail.net (vie01a-dmta-at01-3.mx.upcmail.net [62.179.121.147]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 491F068AA63 for ; Wed, 23 Mar 2022 22:57:35 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1nX1c3-001NwF-DC for ffmpeg-devel@ffmpeg.org; Wed, 23 Mar 2022 15:05:23 +0100 Received: from ren-mail-psmtp-mg02. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id X1c0nbUOdSgGFX1c0nRtc2; Wed, 23 Mar 2022 15:05:21 +0100 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg02. with ESMTP id X1bln6FSZ8eSWX1blnzIKf; Wed, 23 Mar 2022 15:05:05 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.4 cv=KKE5sHJo c=1 sm=1 tr=0 ts=623b2920 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=vZLi97uOGu7UR666kEIA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 23 Mar 2022 15:05:03 +0100 Message-Id: <20220323140503.26844-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220323140503.26844-1-michael@niedermayer.cc> References: <20220323140503.26844-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfDkkZhY8NV+wkb9IMPC2+4of6V0P5hythrwjAh+pWyWRGfYUI98R+A6MRiJlPsuuNGwjkjWekR8s0qmQWhZNF/40Jhaskk2f4IS9K2u8lTgf5Jdr0HxR BaCl2cl4bnfvzenG/JCpYos5lfPBclW3wK76GoO+2RQYgCxfGAMmDDiEkAuCYrEBycMwAdnVDTGrnA== Subject: [FFmpeg-devel] [PATCH 2/2] avformat/aiffdec: cleanup size handling for extreem cases X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: Michael Niedermayer --- libavformat/aiffdec.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index 5236cc2807..2bdcd1362b 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -53,9 +53,9 @@ static enum AVCodecID aiff_codec_get_id(int bps) } /* returns the size of the found tag */ -static int get_tag(AVIOContext *pb, uint32_t * tag) +static int64_t get_tag(AVIOContext *pb, uint32_t * tag) { - int size; + int64_t size; if (avio_feof(pb)) return AVERROR(EIO); @@ -63,16 +63,16 @@ static int get_tag(AVIOContext *pb, uint32_t * tag) *tag = avio_rl32(pb); size = avio_rb32(pb); - if (size < 0) - size = 0x7fffffff; - return size; } /* Metadata string read */ -static void get_meta(AVFormatContext *s, const char *key, int size) +static void get_meta(AVFormatContext *s, const char *key, int64_t size) { - uint8_t *str = av_malloc(size+1U); + uint8_t *str = NULL; + + if (size < SIZE_MAX) + str = av_malloc(size+1); if (str) { int res = avio_read(s->pb, str, size); @@ -89,7 +89,7 @@ static void get_meta(AVFormatContext *s, const char *key, int size) } /* Returns the number of sound data frames or negative on error */ -static int get_aiff_header(AVFormatContext *s, int size, +static int get_aiff_header(AVFormatContext *s, int64_t size, unsigned version) { AVIOContext *pb = s->pb; @@ -101,9 +101,6 @@ static int get_aiff_header(AVFormatContext *s, int size, unsigned int num_frames; int channels; - if (size == INT_MAX) - return AVERROR_INVALIDDATA; - if (size & 1) size++; par->codec_type = AVMEDIA_TYPE_AUDIO; @@ -215,7 +212,8 @@ static int aiff_probe(const AVProbeData *p) /* aiff input */ static int aiff_read_header(AVFormatContext *s) { - int ret, size, filesize; + int ret; + int64_t filesize, size; int64_t offset = 0, position; uint32_t tag; unsigned version = AIFF_C_VERSION1; @@ -226,7 +224,7 @@ static int aiff_read_header(AVFormatContext *s) /* check FORM header */ filesize = get_tag(pb, &tag); - if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M')) + if (filesize < 4 || tag != MKTAG('F', 'O', 'R', 'M')) return AVERROR_INVALIDDATA; /* AIFF data type */ @@ -253,10 +251,7 @@ static int aiff_read_header(AVFormatContext *s) if (size < 0) return size; - if (size >= 0x7fffffff - 8) - filesize = 0; - else - filesize -= size + 8; + filesize -= size + 8; switch (tag) { case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */ -- 2.17.1 _______________________________________________ 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".