From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id D199B43C5D for ; Thu, 27 Oct 2022 06:51:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6FA8968BB98; Thu, 27 Oct 2022 09:51:35 +0300 (EEST) Received: from mx.sdf.org (mx.sdf.org [205.166.94.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A144568BA32 for ; Thu, 27 Oct 2022 09:51:29 +0300 (EEST) Received: from 0fe0d0aeeda0316b6ab41f3ebbd6173c ([1.145.236.2]) (authenticated (0 bits)) by mx.sdf.org (8.15.2/8.14.5) with ESMTPSA id 29R6pLqe025305 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for ; Thu, 27 Oct 2022 06:51:25 GMT Date: Thu, 27 Oct 2022 17:51:17 +1100 From: Peter Ross To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches References: <1ab7c3994301a243fc64d59d6a08e3a2b364e411.1666774269.git.pross@xvid.org> MIME-Version: 1.0 In-Reply-To: Subject: Re: [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 Content-Type: multipart/mixed; boundary="===============6467695727239162826==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============6467695727239162826== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="gA2J7ZpQOnenBW00" Content-Disposition: inline --gA2J7ZpQOnenBW00 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 26, 2022 at 01:41:57PM +0200, Andreas Rheinhardt wrote: > Peter Ross: > > --- > > libavcodec/eatgq.c | 10 +++++++--- > > 1 file changed, 7 insertions(+), 3 deletions(-) > >=20 > > 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 *av= ctx) > > return 0; > > } > > =20 > > -static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitC= ontext *gb) > > +static int tgq_decode_block(TgqContext *s, int16_t block[64], GetBitCo= ntext *gb) > > { > > const uint8_t *scantable =3D ff_zigzag_direct; > > int i, j, value; > > @@ -73,7 +73,9 @@ static void tgq_decode_block(TgqContext *s, int16_t b= lock[64], GetBitContext *gb > > case 1: > > skip_bits(gb, 2); > > value =3D get_bits(gb, 6); > > - for (j =3D 0; j < value; j++) > > + if (!value) > > + return AVERROR_INVALIDDATA; > > + for (j =3D 0; j < value && i < 64; j++) > > block[scantable[i++]] =3D 0; > > break; > > case 6: > > @@ -100,6 +102,7 @@ static void tgq_decode_block(TgqContext *s, int16_t= block[64], GetBitContext *gb > > } > > } > > block[0] +=3D 128 << 4; > > + return 0; > > } > > =20 > > static void tgq_idct_put_mb(TgqContext *s, int16_t (*block)[64], AVFra= me *frame, > > @@ -161,7 +164,8 @@ static int tgq_decode_mb(TgqContext *s, GetByteCont= ext *gbyte, > > return ret; > > =20 > > for (i =3D 0; i < 6; i++) > > - tgq_decode_block(s, s->block[i], &gb); > > + if ((ret =3D 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 { > >=20 > >=20 >=20 > The '4' case can also overread. But actually I don't like the idea of > adding further checks into the main loop; mind if I send an alternative > solution? please go for it. -- Peter (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B) --gA2J7ZpQOnenBW00 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQSpB+AvpuUM0jTNINJnYHnFrEDdawUCY1oqYQAKCRBnYHnFrEDd a2Z+AKCgT3hXd7rYHyBgtusUpfmIVZWfQgCgxLmJcDw6tmiYQ8BN4bcM7xcjQnI= =oPHT -----END PGP SIGNATURE----- --gA2J7ZpQOnenBW00-- --===============6467695727239162826== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --===============6467695727239162826==--