From patchwork Sat Sep 30 22:30:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44065 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp598886pzf; Sat, 30 Sep 2023 15:31:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi12+5XeEzTSHh66RrAx+ksl+fNoZhBPedvozbn/yYMMp71Vhe8xZK74VB9cmtd82fH19q X-Received: by 2002:a17:906:301b:b0:9a5:b876:b1e3 with SMTP id 27-20020a170906301b00b009a5b876b1e3mr6911561ejz.20.1696113091898; Sat, 30 Sep 2023 15:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696113091; cv=none; d=google.com; s=arc-20160816; b=K/Q3gnxRshs3Qv+t0AkWoIoKWFlFQQJAn4bh9Ya6IYkQei2Dv2W3Z44ed+VuDxh1sm yVQJxeF3wsW62AuPP+O6+V/wkVUiZ/27C1iOjjwgCvDITqagcygDtBhzWvf2u0yhf2z3 5Gvn5uOKdTwm+EeXM7RFjLcPtVkl84oo6NO3DaAadrn2evaOqyYqB0Rp/rZJVqsZxwlc SNZMNJ3NLKYlNqQfYZitP2IhB85IwANJ/3ENZxUApE6zRSCQhffOjLPDX5DZ5zkAp+fx eDb7QE0bgkQKay4vWPUTIAleGDxX9CPXQE566mFB63iehJyGzKpm4Wzrw95c1v01pN9r vu2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=ZF5o/549dkyCKSY7pFvlfDAthOvMBAkVOPcYR9xnGYc=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=lqdkEvpdcRWJsRQKC26kWBzseUHw/5rtbirCnFVEj29FKyRM54rlpexw2toz0isyB1 T7GU2mYUo1kc9AaWRN3dOqBDrB34sH5wqlbSSS+K06LEbsL+FTns0v128cG58nmJATl1 1NhW1j0eXTgAaR6pU+owjLH2MCyley+qkGRY0HwLAtyPSLjKVwzZyNZorOFBsnfnoNzB NAfvvo9HzjNQH5i5PUNIu8C/Mw0SbghbfsHxvor6vI7xO8uTzC3iMhf9mi9oEL9ohCJT JaN/UyhTxApoyiO9QST8Bkl2foVuSfqy2awaMky3/FpHyhnrCoR4N1eYFDvUK/Ia69uJ FHYQ== 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 w4-20020a170906130400b0099364d9f0e0si17533309ejb.540.2023.09.30.15.31.31; Sat, 30 Sep 2023 15:31:31 -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 E1D2E68CD51; Sun, 1 Oct 2023 01:30:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 77CC768CD51 for ; Sun, 1 Oct 2023 01:30:52 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id A2F2940003 for ; Sat, 30 Sep 2023 22:30:51 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 1 Oct 2023 00:30:36 +0200 Message-Id: <20230930223046.22896-5-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230930223046.22896-1-michael@niedermayer.cc> References: <20230930223046.22896-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 05/15] avformat/mov: compute absolute dts difference without overflow in mov_find_next_sample() 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: db79vE8qMyVF Fixes: signed integer overflow: -9223372036854775808 - 9222726413022000000 cannot be represented in type 'long' Fixes: 51896/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-5959420033761280 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 294c864fbd6..369c9b2ffd9 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -8795,12 +8795,13 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) if (msc->pb && msc->current_sample < avsti->nb_index_entries) { AVIndexEntry *current_sample = &avsti->index_entries[msc->current_sample]; int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale); + uint64_t dtsdiff = best_dts > dts ? best_dts - (uint64_t)dts : ((uint64_t)dts - best_dts); av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); if (!sample || (no_interleave && current_sample->pos < sample->pos) || ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && dts != AV_NOPTS_VALUE && - ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || - (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) { + ((dtsdiff <= AV_TIME_BASE && current_sample->pos < sample->pos) || + (dtsdiff > AV_TIME_BASE && dts < best_dts)))))) { sample = current_sample; best_dts = dts; *st = avst;