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 0DCF542868 for ; Tue, 5 Apr 2022 09:59:54 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4687068B0C3; Tue, 5 Apr 2022 12:59:52 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9081B68AE7C for ; Tue, 5 Apr 2022 12:59:45 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E6E10240179 for ; Tue, 5 Apr 2022 11:59:44 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id PAU_l0keKpng for ; Tue, 5 Apr 2022 11:59:44 +0200 (CEST) Received: from lain.red.khirnov.net (lain.red.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.red.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 635542400F5 for ; Tue, 5 Apr 2022 11:59:44 +0200 (CEST) Received: by lain.red.khirnov.net (Postfix, from userid 1000) id 8ED7B1601AD; Tue, 5 Apr 2022 11:59:44 +0200 (CEST) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <20220401104608.10193-2-michael@niedermayer.cc> References: <20220401104608.10193-1-michael@niedermayer.cc> <20220401104608.10193-2-michael@niedermayer.cc> Mail-Followup-To: FFmpeg development discussions and patches Date: Tue, 05 Apr 2022 11:59:44 +0200 Message-ID: <164915278455.21047.416796164909893337@lain.red.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 2/2] avformat/matroskadec: avoid integer overflows in SAR computation 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: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Quoting Michael Niedermayer (2022-04-01 12:46:08) > This ignores >64bit > Alternatively we could support that if it occurs in reality > > Fixes: negation of -9223372036854775808 > Fixes: integer overflows > Fixes: 46072/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-5029840966778880 > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > Signed-off-by: Michael Niedermayer > --- > libavformat/matroskadec.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c > index d97fc33d44..069fba6cf7 100644 > --- a/libavformat/matroskadec.c > +++ b/libavformat/matroskadec.c > @@ -2886,11 +2886,14 @@ static int matroska_parse_tracks(AVFormatContext *s) > mkv_stereo_mode_display_mul(track->video.stereo_mode, &display_width_mul, &display_height_mul); > > if (track->video.display_unit < MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN) { > - av_reduce(&st->sample_aspect_ratio.num, > - &st->sample_aspect_ratio.den, > - st->codecpar->height * track->video.display_width * display_width_mul, > - st->codecpar->width * track->video.display_height * display_height_mul, > - INT_MAX); > + if (track->video.display_width && track->video.display_height && > + st->codecpar->height * (int64_t)display_width_mul < INT64_MAX / track->video.display_width && > + st->codecpar->width * (int64_t)display_height_mul < INT64_MAX / track->video.display_height) Why not move display_{width,height}_mul to the other side of the comparison and avoid wordsize assumptions? This is header parsing, so division performance impact should be negligible. -- Anton Khirnov _______________________________________________ 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".