From patchwork Sat May 12 16:33:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 8927 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp2130731jad; Sat, 12 May 2018 09:35:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpFeVVKewE/UBzpsJloYPubE26SVGyUb7CA0liPDSMz5/be2YykLNAFTM4zewBuUU1clgN8 X-Received: by 2002:a1c:8f8f:: with SMTP id r137-v6mr1468935wmd.103.1526142925337; Sat, 12 May 2018 09:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526142925; cv=none; d=google.com; s=arc-20160816; b=Xz5ueLPrVUBZcr/RVPkkZUAIFpyIrSj3th81dLV2smHMdudVR87+fqx1weywMtAXpE joa9Jwm3/6ru8VS2kt0MzHTE09VkqDdR3bzklpDMEX3nVyO4Q3lWKM1WIjmzND5xRTa5 9kDeyAmh8jzsWcuigIKlNDJPHn0v4bRbAAz76Fnt66ZaHUMwXNYiLbr73POlqinheTsT AmmaOpLvcM1ux4sc8nJSVs7Bl1hyehMYJiySii+qnjMksakvdbyoIo2MCledT20xmmfA JPdPEWltF6xm0NdhUikyp21CHWWvYkXYYmSd97NLn/3cgPINr2YEEkQKpOtl6Q6e5LW8 S0jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=Ni1YISoEBM0v8Mm3AX98QA5ytRJAfYgafzJAcrKUJ8Q=; b=OhjKpNzNU+73yq8W2dBxVYoocbqadP07/sxz7hayQbHybIN+XO8WN4YAkAHGZMAqgG BQGlkA4UcO8j89lPXxeflVwwy0ULphl3SqNsZuqycNd8vhtxz/+4QeYMhxQh/K/snlOr R21QjOUsXvyRh8W0XtgPpA7ofoG0jOg3mlkimjsNMGuU8R1R5fmgD/83E1fbI+vv4XNV S8bnBmBSQJLJ8H0F/KqwxSW1DUzpBKMRHuc/qMSDoO/L+XDzHf/x9g0bCl+a8CU8n6wu 4Suc1ANqNpzUQISnK3Fgr13lOASD0hdekXHjI9eszR1RoY2eDTmg7/BZ7tHQlV7lEU8E qYNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i128-v6si2727428wmd.112.2018.05.12.09.35.25; Sat, 12 May 2018 09:35:25 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D026368A8C4; Sat, 12 May 2018 19:34:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-1.mx.upcmail.net (vie01a-dmta-pe06-1.mx.upcmail.net [84.116.36.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5722968A77D for ; Sat, 12 May 2018 19:34:26 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fHXU7-0007XU-27 for ffmpeg-devel@ffmpeg.org; Sat, 12 May 2018 18:35:03 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id lUaw1x0120S5wYM01Uaxcy; Sat, 12 May 2018 18:34:58 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 12 May 2018 18:33:27 +0200 Message-Id: <20180512163329.18380-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180512163329.18380-1-michael@niedermayer.cc> References: <20180512163329.18380-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/5] avformat/mp3dec: Require probing data to be 50% mp3 frames for low score probing to succeed 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This massively reduces the detection of random data as low score mp3 It may improve security by making it harder to read non multimedia data Signed-off-by: Michael Niedermayer --- libavformat/mp3dec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index a76fe32e59..a26714ebaf 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -71,6 +71,7 @@ static int mp3_read_probe(AVProbeData *p) int max_frames, first_frames = 0; int whole_used = 0; int frames, ret; + int framesizes, max_framesizes; uint32_t header; const uint8_t *buf, *buf0, *buf2, *end; @@ -80,11 +81,12 @@ static int mp3_read_probe(AVProbeData *p) buf0++; max_frames = 0; + max_framesizes = 0; buf = buf0; for(; buf < end; buf= buf2+1) { buf2 = buf; - for(frames = 0; buf2 < end; frames++) { + for(framesizes = frames = 0; buf2 < end; frames++) { MPADecodeHeader h; header = AV_RB32(buf2); @@ -92,8 +94,10 @@ static int mp3_read_probe(AVProbeData *p) if (ret != 0) break; buf2 += h.frame_size; + framesizes += h.frame_size; } max_frames = FFMAX(max_frames, frames); + max_framesizes = FFMAX(max_framesizes, framesizes); if(buf == buf0) { first_frames= frames; if (buf2 == end + sizeof(uint32_t)) @@ -104,11 +108,11 @@ static int mp3_read_probe(AVProbeData *p) // issues with MPEG-files! if (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1; else if(max_frames>200)return AVPROBE_SCORE_EXTENSION; - else if(max_frames>=4 && max_frames >= p->buf_size/10000) return AVPROBE_SCORE_EXTENSION / 2; + else if(max_frames>=4 && p->buf_size < 2*max_framesizes) return AVPROBE_SCORE_EXTENSION / 2; else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 2*ff_id3v2_tag_len(buf0) >= p->buf_size) return p->buf_size < PROBE_BUF_MAX ? AVPROBE_SCORE_EXTENSION / 4 : AVPROBE_SCORE_EXTENSION - 2; else if(first_frames > 1 && whole_used) return 5; - else if(max_frames>=1 && max_frames >= p->buf_size/10000) return 1; + else if(max_frames>=1 && p->buf_size < 2*max_framesizes) return 1; else return 0; //mpegps_mp3_unrecognized_format.mpg has max_frames=3 }