From patchwork Fri Oct 2 21:07:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 22702 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 22B0C44B89C for ; Sat, 3 Oct 2020 00:08:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF922689CFF; Sat, 3 Oct 2020 00:08:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-1.mx.upcmail.net (vie01a-dmta-pe01-1.mx.upcmail.net [62.179.121.154]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C80F46881C8 for ; Sat, 3 Oct 2020 00:08:10 +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 1kOSHi-0000IE-1u for ffmpeg-devel@ffmpeg.org; Fri, 02 Oct 2020 23:08:10 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id OSGjkIepOIr7GOSGjk3lqN; Fri, 02 Oct 2020 23:07:10 +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=4iN1Uus1NaVx7lkBA6QA:9 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=jd6J4Gguk5HxikPWLKER:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 2 Oct 2020 23:07:09 +0200 Message-Id: <20201002210709.15688-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfDyZFlLhk+YMkT8wPL+sEeWyGdoIxM4NGZ1mfyq0RdE+d6yiSzGMJxNmHvZcWnr1SFWoA6hXHgeiB4u/rgYAr21i5MbCx5aX8cMUipjxC8Ax/+jNqk8k FLaPtRd6wjjcNV0yOjUEJRaTaRKdI91L6OHQpUaQ9qCvQK+33PiMfaRT Subject: [FFmpeg-devel] [PATCH] avcodec/mobiclip: Check that Motion vectors are within the input 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" The MV checks did not consider the width and height of the block, also they had some off by 1 errors. This resulted in undefined behavior and crashes. This commit instead errors out on these Fixes: out of array read Fixes: 26080/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MOBICLIP_fuzzer-5758146355920896 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/mobiclip.c | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c index f890cb2599..a03ef8fb7d 100644 --- a/libavcodec/mobiclip.c +++ b/libavcodec/mobiclip.c @@ -1189,14 +1189,14 @@ static int predict_motion(AVCodecContext *avctx, dst_linesize = s->pic[s->current_pic]->linesize[i]; dst = s->pic[s->current_pic]->data[i] + offsetx + offsety * dst_linesize; + if (offsetx + (mv.x >> 1) < 0 || + offsety + (mv.y >> 1) < 0 || + offsetx + width + (mv.x + 1 >> 1) > fwidth || + offsety + height + (mv.y + 1 >> 1) > fheight) + return AVERROR_INVALIDDATA; + switch (method) { case 0: - if (offsety + (mv.y >> 1) < 0 || - offsety + (mv.y >> 1) >= fheight || - offsetx + (mv.x >> 1) < 0 || - offsetx + (mv.x >> 1) >= fwidth) - return AVERROR_INVALIDDATA; - src = s->pic[sidx]->data[i] + offsetx + (mv.x >> 1) + (offsety + (mv.y >> 1)) * src_linesize; for (int y = 0; y < height; y++) { @@ -1207,12 +1207,6 @@ static int predict_motion(AVCodecContext *avctx, } break; case 1: - if (offsety + (mv.y >> 1) < 0 || - offsety + (mv.y >> 1) >= fheight || - offsetx + (mv.x >> 1) < 0 || - offsetx + (mv.x >> 1) >= fwidth) - return AVERROR_INVALIDDATA; - src = s->pic[sidx]->data[i] + offsetx + (mv.x >> 1) + (offsety + (mv.y >> 1)) * src_linesize; for (int y = 0; y < height; y++) { @@ -1225,12 +1219,6 @@ static int predict_motion(AVCodecContext *avctx, } break; case 2: - if (offsety + (mv.y >> 1) < 0 || - offsety + (mv.y >> 1) >= fheight - 1 || - offsetx + (mv.x >> 1) < 0 || - offsetx + (mv.x >> 1) >= fwidth) - return AVERROR_INVALIDDATA; - src = s->pic[sidx]->data[i] + offsetx + (mv.x >> 1) + (offsety + (mv.y >> 1)) * src_linesize; for (int y = 0; y < height; y++) { @@ -1243,12 +1231,6 @@ static int predict_motion(AVCodecContext *avctx, } break; case 3: - if (offsety + (mv.y >> 1) < 0 || - offsety + (mv.y >> 1) >= fheight - 1 || - offsetx + (mv.x >> 1) < 0 || - offsetx + (mv.x >> 1) >= fwidth) - return AVERROR_INVALIDDATA; - src = s->pic[sidx]->data[i] + offsetx + (mv.x >> 1) + (offsety + (mv.y >> 1)) * src_linesize; for (int y = 0; y < height; y++) {