From patchwork Thu Jun 8 17:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42018 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp564503pzb; Thu, 8 Jun 2023 10:18:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6q8HoGoCP+Fdam/Ai4nlU9V3YxGJUPISfH339vA8bBx9xlDOZKfKRJ1WLpmhjDechGOzw7 X-Received: by 2002:a17:907:e92:b0:966:4d75:4a44 with SMTP id ho18-20020a1709070e9200b009664d754a44mr483520ejc.24.1686244738335; Thu, 08 Jun 2023 10:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686244738; cv=none; d=google.com; s=arc-20160816; b=YF1J9Li4+RT5EKscfB1EhUrhSCZEEAg+iYi2XNSr33VHyFNXKjM7Et5YuYZlEYcspM gNqvkAiZReUcGftBNUUpT74yc9anMr5gme5yq4dezrUbT42xYyGkXfMB2ztu7lm99g7m xBE2uPrNuaE0tWpRSg87sXkdUVKTjenfC7RClfJ23mAePjfoYH37bgyo0kEtzP2dxXk2 ugDoR/7w2fnbhu06lwfQT8/GYAjpZGn0tRaHXz4QMnplbgN0gpKQroOmhlece9EUFSgs 1hAU53ngvXGo4BsFVlYk6LSdTi0y3wmKdwhVZzMjgMJrs2KGanzqidDipBdVgSk2xhn0 ITjg== 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=HF+7UQGu7rxdWaiLGtuzJHKUOOuwEizdbGxjExcJKtY=; b=m66ITvGi3r2dMHGWIoyrS8Hw9dI2peclReqYRQBJGU0YX90vAzXtMtoaRBdoI+CR6z 1B9W+uDIR5z0ovJJ1HlwbgDnBhUtsE2RVpQ2rCzRAiAXQsdpjDqLh9yoPVR6uR6QtiRk ++GG8+8gJtz5bY1OEvOT0bw7OaCWmcxKi7s89kRMrPm4AMWDHhfb+TDAXKdePdziip7l p1UuW2ZpVu5rDNLPRPIg146dy4D4t2kZnssdm4MhEltNNdbadUn5iMTH4gj1bRTUlClq XsvFptpNpxTUQCw+ks5OtwZ96109WxdlUetr/qUkQQSnXnMyJm3iW6LMHwKF4dcd7bG5 uP/A== 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 y25-20020a170906915900b009745ee66afcsi107473ejw.411.2023.06.08.10.18.58; Thu, 08 Jun 2023 10:18:58 -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 E6E9D68C321; Thu, 8 Jun 2023 20:18:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-02-1.mymagenta.at (mail-02-1.mymagenta.at [80.109.253.248]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3116A68C2D0 for ; Thu, 8 Jun 2023 20:18:28 +0300 (EEST) Received: from [192.168.232.135] (helo=ren-mail-psmtp-mg01.) by mail-02.mymagenta.at with esmtp (Exim 4.93) (envelope-from ) id 1q7JHH-00FzEH-OP for ffmpeg-devel@ffmpeg.org; Thu, 08 Jun 2023 19:18:27 +0200 Received: from localhost ([84.115.40.24]) by ren-mail-psmtp-mg01. with ESMTP id 7JHGqe19fOG5Z7JHGqGBHy; Thu, 08 Jun 2023 19:18:26 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 84.115.40.24 X-CNFS-Analysis: v=2.4 cv=KJo5sHJo c=1 sm=1 tr=0 ts=64820d62 a=4thelYDX6rwh+ygQwvsI+Q==:117 a=4thelYDX6rwh+ygQwvsI+Q==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=NEAV23lmAAAA:8 a=XHJqly81KHHAeRfHM8AA:9 a=007GpJTbgYf-BIa_CBI3:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 8 Jun 2023 19:18:25 +0200 Message-Id: <20230608171825.6575-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230608171825.6575-1-michael@niedermayer.cc> References: <20230608171825.6575-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4xfGj9YK3SS/XvTeozfJ3diLP0BFT98CA+2ID/uyncOLb1EFuVNgv5kAGZi7LYC6yxjRkNutiwm1svBkkQ4iK+UYkQQoOmmt+oMp/A9pNAWV/MDsg/fi+b ZnImDJfIHd4TsU/R3tebopU99pKKtlhVSnt5OcgiIPmEBAHXdI6NfV9fEueFc9hVidluuvzQHARq9Q== Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/mpegvideo_dec: Add NULL pointer checks to MPV_motion_lowres() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: mihlRd7kdct8 This makes the null pointer checks match mpv_motion_internal() Fixes: NULL pointer dereference Fixes: 59671/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG1VIDEO_fuzzer-4993004566609920 Fixes: 59678/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEGVIDEO_fuzzer-4893168991338496 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/mpegvideo_dec.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index c87ca77ae6..fcca147cd6 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -885,10 +885,9 @@ static inline void MPV_motion_lowres(MpegEncContext *s, s->mv[dir][1][0], s->mv[dir][1][1], block_s, mb_y); } else { - if (s->picture_structure != s->field_select[dir][0] + 1 && - s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) { + if ( s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field + || !ref_picture[0]) { ref_picture = s->current_picture_ptr->f->data; - } mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, s->field_select[dir][0], @@ -901,8 +900,9 @@ static inline void MPV_motion_lowres(MpegEncContext *s, for (int i = 0; i < 2; i++) { uint8_t *const *ref2picture; - if (s->picture_structure == s->field_select[dir][i] + 1 || - s->pict_type == AV_PICTURE_TYPE_B || s->first_field) { + if ((s->picture_structure == s->field_select[dir][i] + 1 || + s->pict_type == AV_PICTURE_TYPE_B || s->first_field) && + ref_picture[0]) { ref2picture = ref_picture; } else { ref2picture = s->current_picture_ptr->f->data; @@ -933,6 +933,9 @@ static inline void MPV_motion_lowres(MpegEncContext *s, pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; } } else { + if (!ref_picture[0]) { + ref_picture = s->current_picture_ptr->f->data; + } for (int i = 0; i < 2; i++) { mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, s->picture_structure != i + 1,