From patchwork Wed Oct 26 08:51:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Ross X-Patchwork-Id: 39013 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:85a8:b0:a2:d5a7:ad9d with SMTP id s40csp74690pzd; Wed, 26 Oct 2022 01:51:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4m7STV8CzOZ7xGXbYxb9/K4275nYaCcm6A5tXu98L861k2kh4EzmCs1VdkrZzlBREjYdDD X-Received: by 2002:a17:907:2672:b0:780:8bb5:25a3 with SMTP id ci18-20020a170907267200b007808bb525a3mr36101897ejc.281.1666774313060; Wed, 26 Oct 2022 01:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666774313; cv=none; d=google.com; s=arc-20160816; b=IlBuF8TXjx8pD2CB2eJ38+boSSgmibKe4WbZnEVLpy/byGaJqdenDAMS2NxvcySz6f 7GcvBEjHZ2v7m4Fe3Ae50NBF7lO+7LVo50JU5iLHSzKAtPh5FS7I5NzJDpiFi55K4I20 ry79gNZZ2cWpt7GqQFZNMeSmFgvF3z+kyyZ+AmZY+INRrAET9eaRCGs8jFbWwxln7OVK sY3lgrNdInxJPoveaByNcQw0Uxg/RAmey41+EjWGl2bMNCckjNzBffiZqIAN1GRSz0rD E5b+CmzyFtUlMbP4e3OvidCmZMjSLPMciWmXKzDr8PZRz85+RnCLfvOm6bI65754QZ67 0Duw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:delivered-to; bh=JVveJSsnobjHxBDu4OSYLUuq17qnOj3HU+Tkzvd6WUQ=; b=M9mRDRYzPB9/LMoC4RLKQxRrwjZfwe03HXm9Nf3rCqxpJ2/cP/ealFIk0DBZJaEZxe DvxKpQLE/eljQ9MntG9eM+uuYwnBV8hsHRBfa45livip01pltMZrZjm8VXHPXMGiQjBJ KpbkpO0zwjpHvPcALDxGnM7JFpsXoQhpNRB9MbhubQ7qA1R9WrwjKvdTFFUUTTtRNoCv nnpsFDVCh0Xd5aI6a8pjySX0H43bQyPgrBVqeEOj5yxzpO0QAZRVdbJAhlQYhdJvv4yg EixXMpKV3dkw5MMCezFrHzlS8wt7LseV5MEG6yRtVSQq8gHK1TWPmQUzKRAYI9B7QJCJ udxQ== 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 u10-20020a170906b10a00b007897abd2d17si4657606ejy.468.2022.10.26.01.51.48; Wed, 26 Oct 2022 01:51:53 -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 29E3668BB4C; Wed, 26 Oct 2022 11:51:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 611C968B61A for ; Wed, 26 Oct 2022 11:51:38 +0300 (EEST) Received: from bdf1c2b75a6ee6b82f766cd557e6dab7 ([1.145.236.2]) (authenticated (0 bits)) by mx.sdf.org (8.15.2/8.14.5) with ESMTPSA id 29Q8pT6d025534 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for ; Wed, 26 Oct 2022 08:51:33 GMT Date: Wed, 26 Oct 2022 19:51:26 +1100 From: Peter Ross To: ffmpeg-devel@ffmpeg.org Message-ID: <1ab7c3994301a243fc64d59d6a08e3a2b364e411.1666774269.git.pross@xvid.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/eatgq: prevent out of bounds memory access and endless loop 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: C+TnoaVtIH0b --- libavcodec/eatgq.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c index 89e9f20880..fdda8286ef 100644 --- a/libavcodec/eatgq.c +++ b/libavcodec/eatgq.c @@ -56,7 +56,7 @@ static av_cold int tgq_decode_init(AVCodecContext *avctx) return 0; } -static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb) +static int tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb) { const uint8_t *scantable = ff_zigzag_direct; int i, j, value; @@ -73,7 +73,9 @@ static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb case 1: skip_bits(gb, 2); value = get_bits(gb, 6); - for (j = 0; j < value; j++) + if (!value) + return AVERROR_INVALIDDATA; + for (j = 0; j < value && i < 64; j++) block[scantable[i++]] = 0; break; case 6: @@ -100,6 +102,7 @@ static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb } } block[0] += 128 << 4; + return 0; } static void tgq_idct_put_mb(TgqContext *s, int16_t (*block)[64], AVFrame *frame, @@ -161,7 +164,8 @@ static int tgq_decode_mb(TgqContext *s, GetByteContext *gbyte, return ret; for (i = 0; i < 6; i++) - tgq_decode_block(s, s->block[i], &gb); + if ((ret = tgq_decode_block(s, s->block[i], &gb)) < 0) + return ret; tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y); bytestream2_skip(gbyte, mode); } else {