From patchwork Tue Mar 26 02:30:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 47476 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c889:b0:1a3:b6bb:3029 with SMTP id hb9csp1556941pzb; Mon, 25 Mar 2024 19:31:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXisY162AS3WB/qwhcioER2YAc7OtAQdUbv3nCTTNE9Chr8BOTImnp8cPgaL9+NRKCp2jzWQyGbXMYxt3vdO1r7gHRQLflouXF0BA== X-Google-Smtp-Source: AGHT+IE9H6DMM2I3nseH74bZ+eeiIu1uMPpMUBLovnanbngdtz0QIoZ2jyeAysq/z2YYCo8pB363 X-Received: by 2002:a50:ccd0:0:b0:567:2a22:6e86 with SMTP id b16-20020a50ccd0000000b005672a226e86mr6589508edj.22.1711420267493; Mon, 25 Mar 2024 19:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711420267; cv=none; d=google.com; s=arc-20160816; b=d3R4+OyUnIC3cZZRiMYCMQ3BTp1rg/FgjRw4+Gs3NS7xSTWqdGApMYv1qBZgbf9D0Y EMHtbeNNXooAG7T4sdAviLGwr3btwECCFPsQzefB8anv1ayhKi8sOwnDzHzgz57R0H2b o45weC33276XEOjiyVFb8TgLzgi13Qz+IboJtoEJXieLyLvT/S2Zkftxdd/hG0FG6onO 9pRaZ8uLQBJjMJ6MlLqy6WnUEopMF98mL2PuAohCNsj9CKXl0yzCoSRbjMosSs/2gL0p XJ3ltwjLCMA0a2xnng0MOqeLCFsYS0JO5Pz7kLJSFch80jfFeCtd2vB7cz24SOnaGqIS oV1Q== 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:dkim-signature :delivered-to; bh=Tymu6yl0v8wOBl+xYMMh7JJXOmrI3RUXGdZdBDGqX3w=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=IV1zcKsdqLEqgiGc+w44xOl5yepaxOe8wKaQnZiE8lW4G5jAP+vwzsVeSfQfsxRg9d paN+CZ/NYpxQP8S9qi/sWNadYkdVccNxCyVQsj51B104edrUO17jinn8GkAGMdhGgb69 cVakmPMp38jV23OK0gwUgDgZ2na+DWCfk/IOp3y1iEMfLDQR7XGj10VCSncC2ubfz2uU 5NPpNJUgonZiQOENhDtDQIW9QfJCoBNoAyHcQmMe3CW86u1AtBsZCjiPniScDblmHVFb EwwwEGu8KV4dnXpwljf5eXa+H2JPWCh23h3Ea+Vp4pWg2x/hODgykxbl0luftn06PsL1 xAXA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=BFJkV3BP; 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 v11-20020a056402348b00b0056b98658338si3070522edc.248.2024.03.25.19.31.07; Mon, 25 Mar 2024 19:31:07 -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; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=BFJkV3BP; 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 BCDB168D5C4; Tue, 26 Mar 2024 04:31:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8CB1468D4A5 for ; Tue, 26 Mar 2024 04:30:58 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id DC34B60002 for ; Tue, 26 Mar 2024 02:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1711420258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc; bh=IqI6J08s+ZE23X2CcSYim/nJhz7Z20QxLYA45Lv/SFw=; b=BFJkV3BPooWOb2lhIF7f19+mTnnUgRoRxx2iqJDtSBXIcgFbGYLO6BkhWCinEvhjY/AJi1 ljyuq2cHl+2ptQv8BzO9Vfcqov8VxHHr2GTGldsI9/b/iknrv22qUh8vYpJ0d5OCKH+QK3 ynQhKspkyBsiYlgtrMDCmVbbGhMhPfGgcH4XGNA2Eo6EmKnTjA2590M2Ylex4LEQqBKck9 wdc6PjXWKx8QAgCJ4JA24GljnhvSw+49D4uBFQLHHocmSyTVdIvDF3hh3Cuin7eihRQDDa OQMBbhrVieySHEYLzJkUa/glys0/hqoSJHw2LUIglSXoc2XVj9UWgnlhd09QVQ== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 26 Mar 2024 03:30:50 +0100 Message-Id: <20240326023056.20548-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/7] avcodec/hcadec: do not set hfr_group_count to invalid values 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: NbVxP3FsJXbr Fixes: 62285/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HCA_fuzzer-6247136417087488 Fixes: out of array write Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/hcadec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavcodec/hcadec.c b/libavcodec/hcadec.c index 026b998341c..8c8c235f7b3 100644 --- a/libavcodec/hcadec.c +++ b/libavcodec/hcadec.c @@ -212,6 +212,7 @@ static int init_hca(AVCodecContext *avctx, const uint8_t *extradata, int8_t r[16] = { 0 }; unsigned b, chunk; int version, ret; + unsigned hfr_group_count; init_flush(avctx); @@ -336,11 +337,12 @@ static int init_hca(AVCodecContext *avctx, const uint8_t *extradata, if (c->total_band_count < c->base_band_count) return AVERROR_INVALIDDATA; - c->hfr_group_count = ceil2(c->total_band_count - (c->base_band_count + c->stereo_band_count), + hfr_group_count = ceil2(c->total_band_count - (c->base_band_count + c->stereo_band_count), c->bands_per_hfr_group); - if (c->base_band_count + c->stereo_band_count + (unsigned long)c->hfr_group_count > 128ULL) + if (c->base_band_count + c->stereo_band_count + (uint64_t)hfr_group_count > 128ULL) return AVERROR_INVALIDDATA; + c->hfr_group_count = hfr_group_count; for (int i = 0; i < avctx->ch_layout.nb_channels; i++) { c->ch[i].chan_type = r[i];