From patchwork Tue Sep 22 08:33:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 22558 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 BDE4C44A130 for ; Tue, 22 Sep 2020 11:40:02 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9DBCE68B411; Tue, 22 Sep 2020 11:40:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-2.mx.upcmail.net (vie01a-dmta-pe01-2.mx.upcmail.net [62.179.121.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0EAA568B3F2 for ; Tue, 22 Sep 2020 11:39:56 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1kKdkd-0003tS-0B for ffmpeg-devel@ffmpeg.org; Tue, 22 Sep 2020 10:34:15 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id KdjekmHFAIr7GKdjekUXVz; Tue, 22 Sep 2020 10:33:15 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=QN4WuTDL c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=aHPAOpOMp3bz7J-pMyMA:9 a=0bXxn9q0MV6snEgNplNhOjQmxlI=:19 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=jd6J4Gguk5HxikPWLKER:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 22 Sep 2020 10:33:14 +0200 Message-Id: <20200922083314.1467-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfKLCULcBrtU10s55/ASKG3sdETELfpugtpAK8p2tP50DmO67t0XX++mSXkfOhoLk2YdVm1KObuSyet9KVoPc2BocQ0SdE/VXoDoqucZIvnJzIOy/DDFm 8hg8CSBxVUi8UeC04rZ5LvDPX4GCGqD7u+89ir7yxUTE7Bct4x1yv5o/ Subject: [FFmpeg-devel] [PATCH] avcodec/mpeg12dec: Limit maximum A53 CC size 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 is more than 10 times the size of the largest i found. And also alot more than our encoder could handle (our encoder is limited to max 31) Without any limit megabyte+ sized blocks can be reallocated millions of times. Sadly the SCTE-20 spec does not seem to contain any hard limit directly, so this limit here is arbitrary Fixes: Timeout (25sec -> 152ms) Fixes: 25714/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG2VIDEO_fuzzer-5713633336885248 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/mpeg12dec.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index ab470187a1..5884c6fd17 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -50,6 +50,8 @@ #include "version.h" #include "xvmc_internal.h" +#define A53_MAX_CC_COUNT 2000 + typedef struct Mpeg1Context { MpegEncContext mpeg_enc_ctx; int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ @@ -2246,7 +2248,7 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, * UINT64_C(3)); int ret; - if (new_size > INT_MAX) + if (new_size > 3*A53_MAX_CC_COUNT) return AVERROR(EINVAL); ret = av_buffer_realloc(&s1->a53_buf_ref, new_size); @@ -2269,7 +2271,7 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0; const uint64_t new_size = (old_size + cc_count * UINT64_C(3)); - if (new_size > INT_MAX) + if (new_size > 3*A53_MAX_CC_COUNT) return AVERROR(EINVAL); ret = av_buffer_realloc(&s1->a53_buf_ref, new_size); @@ -2339,7 +2341,7 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx, int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0; const uint64_t new_size = (old_size + cc_count * UINT64_C(6)); - if (new_size > INT_MAX) + if (new_size > 3*A53_MAX_CC_COUNT) return AVERROR(EINVAL); ret = av_buffer_realloc(&s1->a53_buf_ref, new_size);