From patchwork Sun Sep 16 00:27:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 10331 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp2091463jap; Sat, 15 Sep 2018 17:28:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY0ybvbrXzcSAQtzmkliyrg13oQ2MfL6kDj12xq45xoLXqqD1o/qDnrt/AOHzJhQfK3VXy4 X-Received: by 2002:adf:8167:: with SMTP id 94-v6mr14598265wrm.127.1537057708351; Sat, 15 Sep 2018 17:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537057708; cv=none; d=google.com; s=arc-20160816; b=RrgwmxhBFjSB8F4NGznjLf6OzqvJkPow7+1sWa5iva2Kl1agr68TdRnhu14xYdmtwW 2onSR67MTuFI6Xhh687/wl48y73M0BgpbrT/ofjzhjUOzTu001j0NakBJzV5y+4ATr4r QbwdJp8NPoWjwKSvJjQJ9hP5zj3oC64jmxB5vm/iB5jkbCTP1h4YcqgUrtmEusCvmrP2 153hjOpboE8cEWjrPKynU3EIKzX/H2/V1Z2rRtgH1ifGyIkEAWQleWf52GpDh7B/0cj9 XRWVYeOQeE6OqtD2tTYieRCqgApA7fm/Ej2QfkWXXLsNsEbCFUT39k1gXGQzDI0dkmPV 011Q== 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; bh=ScvDq0aEGu7pz77JsryfMcf4AgSrnTHc00FIg/yA5/o=; b=y6us91rSGqfYYX8NtRCSCdKvnNE5f3Pqlbvf6X/azWmjK32gDcaA0S92iMZ+2LP6O0 xcpt2Dd32QFmetJtzBjkf2Jrp9twRBFvN3jhPjMeXK9lk7Uu5hHdON0MJOlHhwi2d7tY IwkFjB207sap6LmxgQUS7h3bCBQTBhFOL2fcSm6Tbghe8j2rc8Hyp04QIAd8sSK6ff8J /pD1WhJQdLssH9t4HjomO9W3eVrt/eA1FHBgFHBmLNiOLUtyPTu6rLsksAcuG2l2Poan UXCNEYB7P3bJmu7gORPkAcLKVjFP6+0W+xi7U6BZYNwjD9k/2eTQRsq0MPy0AB3G6glX ETHQ== 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 k13-v6si10118781wrl.87.2018.09.15.17.28.27; Sat, 15 Sep 2018 17:28:28 -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 BEC6868A427; Sun, 16 Sep 2018 03:28:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-2.mx.upcmail.net (vie01a-dmta-pe06-2.mx.upcmail.net [84.116.36.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C4E7668A36E for ; Sun, 16 Sep 2018 03:28:07 +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 1g1KvC-0007Wr-W3 for ffmpeg-devel@ffmpeg.org; Sun, 16 Sep 2018 02:28:18 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id c0UH1y00u0S5wYM010UJux; Sun, 16 Sep 2018 02:28:18 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 16 Sep 2018 02:27:38 +0200 Message-Id: <20180916002738.7513-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180916002738.7513-1-michael@niedermayer.cc> References: <20180916002738.7513-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/zmbv: Check that the raw input is large enough to contain MVs or an intra frame 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" Fixes: Timeout Fixes: 10182/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ZMBV_fuzzer-6245951174344704 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/zmbv.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c index 9e27a2caad..1133bdf7ba 100644 --- a/libavcodec/zmbv.c +++ b/libavcodec/zmbv.c @@ -409,6 +409,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac int zret = Z_OK; // Zlib return code int len = buf_size; int hi_ver, lo_ver, ret; + int min_size; /* parse header */ if (len < 1) @@ -510,7 +511,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac memset(c->prev, 0, avctx->width * avctx->height * (c->bpp / 8)); c->decode_intra= decode_intra; } - + if (c->flags & ZMBV_KEYFRAME) { + min_size = avctx->width * avctx->height * (c->bpp / 8); + } else { + min_size = (c->bx * c->by * 2 + 3) & ~3; + } if (!c->decode_intra) { av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n"); return AVERROR_INVALIDDATA; @@ -524,6 +529,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac av_log(avctx, AV_LOG_ERROR, "Buffer too small\n"); return AVERROR_INVALIDDATA; } + if (min_size > len) { + av_log(avctx, AV_LOG_ERROR, "input too small\n"); + return AVERROR_INVALIDDATA; + } memcpy(c->decomp_buf, buf, len); } else { // ZLIB-compressed data c->zstream.total_in = c->zstream.total_out = 0;