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 EFD0140437 for ; Mon, 20 Dec 2021 21:36:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1CC9B68AF8B; Mon, 20 Dec 2021 23:36:10 +0200 (EET) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D474C68A62B for ; Mon, 20 Dec 2021 23:36:02 +0200 (EET) Received: from localhost (213-47-68-29.cable.dynamic.surfer.at [213.47.68.29]) (Authenticated sender: michael@niedermayer.cc) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 2602F240003 for ; Mon, 20 Dec 2021 21:36:01 +0000 (UTC) Date: Mon, 20 Dec 2021 22:36:01 +0100 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20211220213601.GZ2829255@pb2> References: <20211220204609.199-1-ffmpeg@gyani.pro> <0834efe9-7ae0-301f-4bc3-f58222b6e536@gyani.pro> <20211220212153.GY2829255@pb2> MIME-Version: 1.0 In-Reply-To: <20211220212153.GY2829255@pb2> Subject: Re: [FFmpeg-devel] [PATCH v2] avformat/mov: abort reading truncated stts 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="===============0589966455904732600==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============0589966455904732600== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="F6hBGECwN4mEHuY0" Content-Disposition: inline --F6hBGECwN4mEHuY0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 20, 2021 at 10:21:53PM +0100, Michael Niedermayer wrote: > On Tue, Dec 21, 2021 at 02:31:33AM +0530, Gyan Doshi wrote: > >=20 > >=20 > > On 2021-12-21 02:24 am, Andreas Rheinhardt wrote: > > > Gyan Doshi: > > > >=20 > > > > On 2021-12-21 02:18 am, Andreas Rheinhardt wrote: > > > > > Gyan Doshi: > > > > > > Avoids overreading the box and ingesting absurd values into stt= s_data > > > > > > --- > > > > > > =A0 libavformat/mov.c | 5 +++++ > > > > > > =A0 1 file changed, 5 insertions(+) > > > > > >=20 > > > > > > diff --git a/libavformat/mov.c b/libavformat/mov.c > > > > > > index 2aed6e80ef..5a7209837f 100644 > > > > > > --- a/libavformat/mov.c > > > > > > +++ b/libavformat/mov.c > > > > > > @@ -2935,6 +2935,11 @@ static int mov_read_stts(MOVContext *c, > > > > > > AVIOContext *pb, MOVAtom atom) > > > > > > =A0=A0=A0=A0=A0 avio_rb24(pb); /* flags */ > > > > > > =A0=A0=A0=A0=A0 entries =3D avio_rb32(pb); > > > > > > =A0 +=A0=A0=A0 if (atom.size < 8 + (int64_t)entries*8) { > > > > > > +=A0=A0=A0=A0=A0=A0=A0 av_log(c->fc, AV_LOG_ERROR, "Truncated S= TTS box for st > > > > > > %d.\n", c->fc->nb_streams-1); > > > > > > +=A0=A0=A0=A0=A0=A0=A0 return AVERROR_INVALIDDATA; > > > > > > +=A0=A0=A0 } > > > > > > + > > > > > > =A0=A0=A0=A0=A0 av_log(c->fc, AV_LOG_TRACE, "track[%u].stts.en= tries =3D %u\n", > > > > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 c->fc->nb_streams-1, e= ntries); > > > > > This might fix the issue with the fuzzer sample Michael gave you,= but > > > > > what would stop the fuzzer (or a malicious adversary) from simply= using > > > > > a gigantic atom size? > > > > Do you want the comparison to switch to a strict inequality? > > > >=20 > > > No, because it might be that the adversary just uses the expected siz= e, > > > so this would not fix anything. > >=20 > > There are real world multi-hour files with large stts boxes, so there i= s no > > robust solution for that, only heuristics. >=20 >=20 > lets take a closer look at the loop you are adding >=20 > sample_count =3D avio_rb32(pb); > sample_duration =3D avio_rb32(pb); >=20 > sc->stts_data[i].count=3D sample_count; > sc->stts_data[i].duration=3D sample_duration; >=20 > for (int j =3D 0; j < sample_count; j++) { This also adds undefined behavior as j overflows when sample_count > INT_MAX thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Dictatorship naturally arises out of democracy, and the most aggravated form of tyranny and slavery out of the most extreme liberty. -- Plato --F6hBGECwN4mEHuY0 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCYcD3PQAKCRBhHseHBAsP q3vfAJ9RwZcNfVjiXV7Jxdj4Cji3mEXA7wCePb5oQIWNfKieu1mkz0Sc3Fyj5Ek= =kYVY -----END PGP SIGNATURE----- --F6hBGECwN4mEHuY0-- --===============0589966455904732600== 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". --===============0589966455904732600==--