From patchwork Fri Sep 15 13:11:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 43744 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca2:b0:149:dfde:5c0a with SMTP id fx34csp305409pzb; Fri, 15 Sep 2023 06:12:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGehSLEE7663OY2OjW+JncIiv4qNX5JFPxzPqIGMfFEChfLLz0c3KvcP9elU6NPY5zJFvDz X-Received: by 2002:a05:6402:8c5:b0:525:53b6:3ef9 with SMTP id d5-20020a05640208c500b0052553b63ef9mr1363185edz.35.1694783543010; Fri, 15 Sep 2023 06:12:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694783542; cv=none; d=google.com; s=arc-20160816; b=gfNhZlZm5zelaiCDsBg6Fu7RB5NC5uFdrUqN15r4yb9lKHUtCM76zZVNp7qjHXJ1YC /Cz4M8tzmPrUw0122kbpmPYNxkT0kWPzAq+ovWCuj6+L9dKkQW7ImlW22QdeBhnjBall NG98Ye7JiB5ExEtlPgT8yR73uWCsS2UCd6CpM/I2/yRlYSiCjXcwpjtValuVRxvOR1ZB h0NnbhTu7bluOznJQInFrabL1bcsWWqoUGVQfVChnvVjqoFd3AEGajaV0ZnTTOBzXE+3 gOGvSSx1REFpb/DfXqLm1tARJ+1Vhh1cYlTNCz/T+RPc+ecniGnu3pB01whFWHOfopFe L1EA== 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:message-id:date:to:from:delivered-to; bh=GI9nIDLnqgzotb7Ac+oyEkGZ2wyQyF6OkwaXUuGbPlY=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=TjvmcOcrLz1hMLj5FQ0zg2wuP+h04sD2ESmPeZB9whlG5laW+Ef+jR5dz3OdAhd/uE +8Eu9uvLl+dHJN/KT4cM8mzWeMgYhlU0IfaVRPMmi1WowUNEAJe+Ai8Do3gdB3dD7ypD Thpk0FLY4gJ8dPoOusuAfe8ylT6OjHbrskBCwDZHlh8MsjtZDDobF/PcfLMXoCDRJat+ xoWR/buacwXhE7oNR38rlixTcc/jn63X7hHQC5pSWW5bEBBRTDDQ1iZwnIp8czHQqqen S0sp5x4z/fK8g5+ds6YViS6zJnAUgp3H6+OssFm3SXNIYmMOFm28TO5rUSxmlSChKde9 SXxQ== 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 n15-20020a056402514f00b0052a40523c4fsi3125103edd.539.2023.09.15.06.11.59; Fri, 15 Sep 2023 06:12:22 -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 1E1E068C768; Fri, 15 Sep 2023 16:11:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CB4D668C6B3 for ; Fri, 15 Sep 2023 16:11:48 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id E534CC0006 for ; Fri, 15 Sep 2023 13:11:47 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 15 Sep 2023 15:11:44 +0200 Message-Id: <20230915131147.5945-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/evc_ps: Check cpb_cnt_minus1 and propagate error 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: 4Mt0wEQm9+MQ Fixes: out of array access Fixes: 60949/clusterfuzz-testcase-minimized-ffmpeg_dem_EVC_fuzzer-5959738853294080 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/evc_ps.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/libavcodec/evc_ps.c b/libavcodec/evc_ps.c index 64384a392c2..7fe13fd32f0 100644 --- a/libavcodec/evc_ps.c +++ b/libavcodec/evc_ps.c @@ -53,6 +53,9 @@ static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl) static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd) { hrd->cpb_cnt_minus1 = get_ue_golomb_31(gb); + if (hrd->cpb_cnt_minus1 >= FF_ARRAY_ELEMS(hrd->cpb_size_value_minus1)) + return AVERROR_INVALIDDATA; + hrd->bit_rate_scale = get_bits(gb, 4); hrd->cpb_size_scale = get_bits(gb, 4); for (int SchedSelIdx = 0; SchedSelIdx <= hrd->cpb_cnt_minus1; SchedSelIdx++) { @@ -71,6 +74,8 @@ static int hrd_parameters(GetBitContext *gb, HRDParameters *hrd) // @see ISO_IEC_23094-1 (E.2.1 VUI parameters syntax) static int vui_parameters(GetBitContext *gb, VUIParameters *vui) { + int ret; + vui->aspect_ratio_info_present_flag = get_bits(gb, 1); if (vui->aspect_ratio_info_present_flag) { vui->aspect_ratio_idc = get_bits(gb, 8); @@ -109,11 +114,18 @@ static int vui_parameters(GetBitContext *gb, VUIParameters *vui) vui->fixed_pic_rate_flag = get_bits(gb, 1); } vui->nal_hrd_parameters_present_flag = get_bits(gb, 1); - if (vui->nal_hrd_parameters_present_flag) - hrd_parameters(gb, &vui->hrd_parameters); + if (vui->nal_hrd_parameters_present_flag) { + ret = hrd_parameters(gb, &vui->hrd_parameters); + if (ret < 0) + return ret; + } + vui->vcl_hrd_parameters_present_flag = get_bits(gb, 1); - if (vui->vcl_hrd_parameters_present_flag) - hrd_parameters(gb, &vui->hrd_parameters); + if (vui->vcl_hrd_parameters_present_flag) { + ret = hrd_parameters(gb, &vui->hrd_parameters); + if (ret < 0) + return ret; + } if (vui->nal_hrd_parameters_present_flag || vui->vcl_hrd_parameters_present_flag) vui->low_delay_hrd_flag = get_bits(gb, 1); vui->pic_struct_present_flag = get_bits(gb, 1); @@ -292,8 +304,11 @@ int ff_evc_parse_sps(GetBitContext *gb, EVCParamSets *ps) } sps->vui_parameters_present_flag = get_bits1(gb); - if (sps->vui_parameters_present_flag) - vui_parameters(gb, &(sps->vui_parameters)); + if (sps->vui_parameters_present_flag) { + ret = vui_parameters(gb, &(sps->vui_parameters)); + if (ret < 0) + goto fail; + } // @note // If necessary, add the missing fields to the EVCParserSPS structure