From patchwork Fri Sep 15 13:11:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 43745 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bca2:b0:149:dfde:5c0a with SMTP id fx34csp305571pzb; Fri, 15 Sep 2023 06:12:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAVBPTBREzOWpd+NF2m86LTHxJ0lGiC9fWaPlmd7uDMpQxLqzchWsjwVqsN1q0tI+tvPSV X-Received: by 2002:aa7:c642:0:b0:522:4764:8baa with SMTP id z2-20020aa7c642000000b0052247648baamr2417500edr.12.1694783556510; Fri, 15 Sep 2023 06:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694783556; cv=none; d=google.com; s=arc-20160816; b=N0xUNuZosqlJt9x4lpvuVUoK1Mdq9GTN2FyeKrigakTBhmddwkoKty4q1PkMvdGUtd pNU4ReQkPXasFejQX1M1wxQqeUw/vHNj+Ax4RUHwPVwManYdKfgQ70l+9EsGf+/OwRtX 3iQDPHsquWhjMRRXbGXdK3heJVtK1iYsjDwc0SSCROueAYfJD8CDLkaJUm+416qHjNvu Hs37dwvn5xxRIDTcm4UA7i3yRxWKrd+Qvy2h+pw5KRbz/qnjIpJ+jhih1JXa6lCxh1tb xD6dJKe9ZWU+eFTZyF+pWYKROJIXl7mxaYJnQgCRQbMM5aqXaeaV6y0hcd5ktXXfeT5O jG0Q== 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=LgAJC/GTceEP2QXcQ6lV6GGnp2chh2kVYt65KlrUA/I=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=hyuIPEZ6YOHGOQ6Jo7+YifoAefDU57xJp1psomnGEFg7tVlS4NoARXICE9ZTT8FgNj vynW8KpMe2Vsz/o0LLW8hevRjJeJEQaFWsxuclBdvOMGaPCf7+02ZVHEejkRO1Es34pM 4kJGTUgAfJiGMn9zbvYfXTfrfONnfLeAIyGSM9qvToyD7aHzcoFRwY6uN1bUd70eTc3P 3c0V9GIYl0sYmh2MXZBfyNJwm8YRqQx2f/RuY0u3qKHJyLLUopu6NsXks/ADBvl2fVPO UEMfpIxLgU/GRlVXhwZaZXbeyuM1LP+jbypIQE+y41k7LLn7J58vY1oByf4orGZ5BOGh BYqw== 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 c12-20020aa7d60c000000b0052a40d398dfsi3132179edr.691.2023.09.15.06.12.13; Fri, 15 Sep 2023 06:12:36 -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 46A6668C7BB; Fri, 15 Sep 2023 16:11:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0FDEF68C765 for ; Fri, 15 Sep 2023 16:11:50 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 3C89EFF80F for ; Fri, 15 Sep 2023 13:11:48 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 15 Sep 2023 15:11:45 +0200 Message-Id: <20230915131147.5945-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230915131147.5945-1-michael@niedermayer.cc> References: <20230915131147.5945-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/evc_ps: Check ref_pic_num and sps_max_dec_pic_buffering_minus1 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: nzU0cx4+u8Y3 Fixes: out of array write Found-by: dongsookim@korea.ac.kr Signed-off-by: Michael Niedermayer --- libavcodec/evc_ps.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libavcodec/evc_ps.c b/libavcodec/evc_ps.c index 7fe13fd32f0..96237ed2911 100644 --- a/libavcodec/evc_ps.c +++ b/libavcodec/evc_ps.c @@ -22,12 +22,15 @@ #include "evc_ps.h" #define EXTENDED_SAR 255 - // @see ISO_IEC_23094-1 (7.3.7 Reference picture list structure syntax) -static int ref_pic_list_struct(GetBitContext *gb, RefPicListStruct *rpl) +static int ref_pic_list_struct(EVCParserSPS *sps, GetBitContext *gb, RefPicListStruct *rpl) { uint32_t delta_poc_st, strp_entry_sign_flag = 0; rpl->ref_pic_num = get_ue_golomb_long(gb); + + if ((unsigned)rpl->ref_pic_num > sps->sps_max_dec_pic_buffering_minus1) + return AVERROR_INVALIDDATA; + if (rpl->ref_pic_num > 0) { delta_poc_st = get_ue_golomb_long(gb); @@ -251,6 +254,8 @@ int ff_evc_parse_sps(GetBitContext *gb, EVCParamSets *ps) sps->max_num_tid0_ref_pics = get_ue_golomb_31(gb); else { sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb_long(gb); + if ((unsigned)sps->sps_max_dec_pic_buffering_minus1 > 16 - 1) + return AVERROR_INVALIDDATA; sps->long_term_ref_pic_flag = get_bits1(gb); sps->rpl1_same_as_rpl0_flag = get_bits1(gb); sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(gb); @@ -261,7 +266,7 @@ int ff_evc_parse_sps(GetBitContext *gb, EVCParamSets *ps) } for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i) - ref_pic_list_struct(gb, &sps->rpls[0][i]); + ref_pic_list_struct(sps, gb, &sps->rpls[0][i]); if (!sps->rpl1_same_as_rpl0_flag) { sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(gb); @@ -270,7 +275,7 @@ int ff_evc_parse_sps(GetBitContext *gb, EVCParamSets *ps) goto fail; } for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i) - ref_pic_list_struct(gb, &sps->rpls[1][i]); + ref_pic_list_struct(sps, gb, &sps->rpls[1][i]); } }