From patchwork Sat Mar 10 21:48:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 7897 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp56360jad; Sat, 10 Mar 2018 13:48:36 -0800 (PST) X-Google-Smtp-Source: AG47ELtEKY3CYLFxPoiievnnfs0ZfeoQuvyH9EYuJaHiv6ig5MeRUnhAbEy7BIGp4zUsaLCEqowx X-Received: by 10.28.212.13 with SMTP id l13mr2044639wmg.123.1520718516634; Sat, 10 Mar 2018 13:48:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520718516; cv=none; d=google.com; s=arc-20160816; b=LqM9QFjoLN4J54WV2LFxbRrax5BQ7L/3OE4yhw8xqFEAYCOYhVr3x8VXQyr+1EdfRH U8bDcJ7N1tBf059kdY1k70oO9Eeh54Aagiku09RnD9Q69DoQV2VzMNXw7WpTqBF2SnUP h0gP6cGYDPRYipjxYUfl+dq9rHCUtzxHJhvzweesO6BXOxl00erXzY89HeAw+RWRA01q H8Fd8hDIHlnATlImlqK2i+ApH29qLjkiH9Sd0Yf3jHBN6UqsYjQ/8aNJvzrNC2jDC53W X7XZL/E2sArqzj5v0jxe6BEDew5uUXmNIQtGKZcEt5mqaNSrgLWlVHvSzgWXyPA/1sg1 Uh6g== 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:message-id:date:to:from:delivered-to :arc-authentication-results; bh=IPnrxNQQ0N0UBzpO8fLGehpwe1Lw3E+T8B2LdbtAzz0=; b=Oh0v5J7fCzv5/09jvfv8S5l1GlAkd2imRd4zVjQvut178MF510VU2F/IalotB1G6dO 6m1Soc7LMd8ncDkDzZWIYUY5SFmkOYc/3KX9DPKtGyBrJX0/sSMChGHVW3S7FiAEjBFg 3peQIGKANeDNTHd4QD0TiB9xw67OkrQ0VOPePnxbTycrAA5HElBjtiKMbJW4BmKceiKh C65+ntSyDMaUstd1SdwITRRg1jLj/2EozgbOg0BCG8vx2863eac8CL2kR7iKicjpyncw ntVDVDygljusH5Are0AUZWKRNKH0VB41Txq8QfbAE3IEpM4Lg1mBBq3n1KAblZuHftCi 75PQ== 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 r35si2554658wrb.482.2018.03.10.13.48.35; Sat, 10 Mar 2018 13:48:36 -0800 (PST) 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 816C468A040; Sat, 10 Mar 2018 23:48:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-3.mx.upcmail.net (vie01a-dmta-pe06-3.mx.upcmail.net [84.116.36.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D7F5768A040 for ; Sat, 10 Mar 2018 23:48:17 +0200 (EET) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1eumLr-0006Kg-C7 for ffmpeg-devel@ffmpeg.org; Sat, 10 Mar 2018 22:48:27 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id LMoS1x00a0S5wYM01MoTlW; Sat, 10 Mar 2018 22:48:27 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 10 Mar 2018 22:48:16 +0100 Message-Id: <20180310214816.4366-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.16.2 Subject: [FFmpeg-devel] [PATCH] avformat/mov: Fix integer overflows related to sample_duration X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Fixes: runtime error: signed integer overflow: -9166684017437101870 + -2495066639299164439 cannot be represented in type Fixes: Chromium bug 791349 Reported-by: Matt Wolenetz Reviewed-by: Matt Wolenetz Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 51228f5df2..b7f9c0cdd1 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2885,14 +2885,19 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) && total_sample_count > 100 && sample_duration/10 > duration / total_sample_count) sample_duration = duration / total_sample_count; - duration+=(int64_t)sample_duration*sample_count; + duration+=(int64_t)sample_duration*(uint64_t)sample_count; total_sample_count+=sample_count; } sc->stts_count = i; - sc->duration_for_fps += duration; - sc->nb_frames_for_fps += total_sample_count; + if (duration > 0 && + duration <= INT64_MAX - sc->duration_for_fps && + total_sample_count <= INT64_MAX - sc->nb_frames_for_fps + ) { + sc->duration_for_fps += duration; + sc->nb_frames_for_fps += total_sample_count; + } if (pb->eof_reached) { av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted STTS atom\n"); @@ -4798,8 +4803,13 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) dts += sample_duration; offset += sample_size; sc->data_size += sample_size; - sc->duration_for_fps += sample_duration; - sc->nb_frames_for_fps ++; + + if (sample_duration <= INT64_MAX - sc->duration_for_fps && + 1 <= INT64_MAX - sc->nb_frames_for_fps + ) { + sc->duration_for_fps += sample_duration; + sc->nb_frames_for_fps ++; + } } if (i < entries) { // EOF found before reading all entries. Fix the hole this would