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 16C4D4999B for ; Mon, 25 Mar 2024 22:54:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A067568D5D9; Tue, 26 Mar 2024 00:54:28 +0200 (EET) Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D20668D457 for ; Tue, 26 Mar 2024 00:54:22 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id A797E1BF204 for ; Mon, 25 Mar 2024 22:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1711407261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+EN9cUJahnG94ryW3DsX65ZSUekVz7yRbS7+KgpCbII=; b=EUK/Chtqx5biMBVpwhzt8ETTQOLQsTLYIZGqwcMOGAwzvlHoJUNx2zV6nD9y8tBNi5//Bi 0PlY/1D7FKaqt0819mh4xRMlbQTwUbUzCWZc93D3qVm+u8oP2dZbr9HB76NA6SEGVxIL84 KFbUPVonp8jgYtwKg6VSPszshkIOr8C71neEYpulXve/m4D70twXrpX79gTDpYZrPlFb9U n1cPnsFmVZDNKO8diwJWN7MfPfma4lW3kLJbSxnRc1khwHdiGEr4l6bdvjfIOUhg7vkHhs ID1rVAFAE4rVz3falXeskxRczzlqKdXn1EKzpAH+eWur/Jcs80LAKcQ+1HuM8g== Date: Mon, 25 Mar 2024 23:54:20 +0100 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20240325225420.GW6420@pb2> References: <20230929232001.23197-1-michael@niedermayer.cc> <20230929232001.23197-4-michael@niedermayer.cc> <20230930163207.GM3543730@pb2> MIME-Version: 1.0 In-Reply-To: <20230930163207.GM3543730@pb2> X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH 4/6] avformat/cafdec: saturate start + size into 64bit 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="===============0179838830238520818==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============0179838830238520818== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4AmHhRG01oNgaYhq" Content-Disposition: inline --4AmHhRG01oNgaYhq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Sep 30, 2023 at 06:32:07PM +0200, Michael Niedermayer wrote: > On Fri, Sep 29, 2023 at 08:41:23PM -0300, James Almer wrote: > > On 9/29/2023 8:19 PM, Michael Niedermayer wrote: > > > Fixes: signed integer overflow: 64 + 9223372036854775803 cannot be re= presented in type 'long long' > > > Fixes: 51896/clusterfuzz-testcase-minimized-ffmpeg_dem_CAF_fuzzer-653= 6881135550464 > > >=20 > > > Found-by: continuous fuzzing process https://github.com/google/oss-fu= zz/tree/master/projects/ffmpeg > > > Signed-off-by: Michael Niedermayer > > > --- > > > libavformat/cafdec.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > >=20 > > > diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c > > > index e92e3279fc6..0e50a3cfe68 100644 > > > --- a/libavformat/cafdec.c > > > +++ b/libavformat/cafdec.c > > > @@ -435,7 +435,7 @@ static int read_packet(AVFormatContext *s, AVPack= et *pkt) > > > /* don't read past end of data chunk */ > > > if (caf->data_size > 0) { > > > - left =3D (caf->data_start + caf->data_size) - avio_tell(pb); > > > + left =3D av_sat_add64(caf->data_start, caf->data_size) - avi= o_tell(pb); > >=20 > > avio_tell(pb) here is guaranteed to be bigger than caf->data_start, whi= ch is > > the offset where the DATA chunk starts, so the result of this calculati= on > > will be <=3D INT64_MAX even if you don't saturate it and instead cast i= t to > > uint64_t. Nonetheless, if the DATA chunk ends at an offset that would n= ot > > fit in an int64_t, then we can't parse it to begin with due to AVIOCont= ext > > API limitations. > >=20 >=20 > > Maybe we should just abort in read_header() if data_start + data_size > > > INT64_MAX, instead of pretending we can parse the file, invalid or not,= by > > saturating values. >=20 > yes ill try that ossfuzz moved the testcases all to another unrelated issues (62276) ill apply this as suggested with the check in read_header() below: diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index 72809fd1de2..07a2939a7a6 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -343,6 +343,9 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 4); /* edit count */ caf->data_start =3D avio_tell(pb); caf->data_size =3D size < 0 ? -1 : size - 4; + if (caf->data_start < 0 || caf->data_size > INT64_MAX - caf->d= ata_start) + return AVERROR_INVALIDDATA; + if (caf->data_size > 0 && (pb->seekable & AVIO_SEEKABLE_NORMAL= )) avio_skip(pb, caf->data_size); found_data =3D 1; [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras --4AmHhRG01oNgaYhq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZgIAnAAKCRBhHseHBAsP q+QGAJkBiKmRG6pdxaBTgch00JIZMUhxLQCeODGs/q7aDsklW1dKFMDmhrmabKo= =NM4v -----END PGP SIGNATURE----- --4AmHhRG01oNgaYhq-- --===============0179838830238520818== 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". --===============0179838830238520818==--