From patchwork Sun Jul 28 20:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 50807 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:16f:b0:489:2eb3:e4c4 with SMTP id h47csp786416vqi; Sun, 28 Jul 2024 13:21:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXFgaQmyXuOBIqnvV26YOcT+lXKRKe4XKUibb3Y7LYrEZpb/wMQ8NfN+23zUyOeISOE16GF51uiZ4wRlhRaskz5d5Drca2Ke+BpTw== X-Google-Smtp-Source: AGHT+IHwq7qZ0Q9lII22dYzBH2YnZMSBxe4tCrBK8AQFBnRgjTmW2yQ+YDGlNPnbp17h860JcGSC X-Received: by 2002:a17:907:1c19:b0:a77:cf9d:f49b with SMTP id a640c23a62f3a-a7d4016584fmr397663866b.54.1722198065736; Sun, 28 Jul 2024 13:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722198065; cv=none; d=google.com; s=arc-20160816; b=INeuBsvNkAZEge7rMh2VELihdZ+1kxzXkxG6MSnrDKtLGzs9GoRKl40skyYIsdHsTG 69p6YTBPGR2MEl6E81QnAknoGZQhTP0bF9UDmr/zH11zpOf/HsUaTvuSF5BGkEUFIq7A qDVGWOw4oT7xu3PfnCIMIz1WkMAnumcXOuZHbOyWp0FLu0TdiLSjxJqHr6+cx9/u7OH/ nf72aLqw7phiPlixOjq5Ln29lodK9mMOmo3enT7CcALmQTRnRh4YlNM/kgtc3eVH4Qib eGzUhzNB17UzduzUaNHygQPMMVCgQBSsmtnL0VHP0bUAIoWyZzrdPyevTEm2r2OlQKXR LEag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=SrHJcKCrpzznZRxmngMlbOqXvM1fZZ3kZbyUrs0otTI=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=cLhZFfcB8Xs+RoyTcESArAk+jGfxGufpgU1gLMELDzoo58TnXszAazCxp5oFHjkr2U asVJ0itLYihvCvqTVGZoY8Kh/6zm2NKQYy1p7ifjHwVk8uzSZvEt6kzpDh7w98HzQGlb 8P1+9Y79FfquyABq0y/skoSDkpYgWHTCdsJbwpgoYpI4P1u/iylui2PpXbW7Lgh0IjnD RGvM1niWpt0sqnYOpb8015D+y5kkC0hbsanMYgiYst7dcALg+Ml6VcWZLcUhbfUxivOK s3lZcQEy+bsjEeWhlEqbfhsiLxPRrVeHQlHZrZKyEt1CMX8EoU9FioRBYjewRCtz0Gx+ JlMQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=pyukbteL; 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 a640c23a62f3a-a7acac60f7dsi542864266b.517.2024.07.28.13.21.05; Sun, 28 Jul 2024 13:21:05 -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; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=pyukbteL; 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 0482868D8BE; Sun, 28 Jul 2024 23:21:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AE9F68D6C2 for ; Sun, 28 Jul 2024 23:20:55 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 7F9781C0002 for ; Sun, 28 Jul 2024 20:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1722198054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KNh2dkUygq3lJBeM2QoaZEdX2vhi/pJgyex0ylx147M=; b=pyukbteL5hZ6dgxBu/GUoGmWDOcs0oUXa2WB8jryvjH1o+A/n9skNedwvyH6RrSg7eO2fK pp3E9//zxL88tPG1xErjv+CqjyIjRA04UW7TYh20OotW2KRDHOtk8rxiK54YhSf9yLdNa9 R201Bb+vY9huPyeGpgm5d97OYZnDX1Crg+vi/D+euX3t/ZANNlgPwyuMLBTFLL+Z3x2jmB 7bQQP5x7gGwv5yWyC7zTOE66MSeqh330mrSG1OemK6SpSJn3YCX84dA+q/cJusMhmS48MS HBkpIaWzMKtAs8rdeea8Bg/au9UA28GO2sYBYVFP9Oj/8Ie8LtqGZGRt8YU/Yw== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 28 Jul 2024 22:20:52 +0200 Message-ID: <20240728202053.3120590-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mov: Avoid overflow in dts 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dh92ARsTFIvo This basically ignores the overflow without undefined behavior, alternatively we could detect and error out Fixes: signed integer overflow: 6310596683470275584 + 7660622966157213696 cannot be represented in type 'long' Fixes: 70433/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-5483347233538048 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index b74e43e2140..403af1bba17 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3472,10 +3472,10 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->stts_data[i].duration = 1; corrected_dts += (delta_magnitude < 0 ? (int64_t)delta_magnitude : 1) * sample_count; } else { - corrected_dts += sample_duration * (int64_t)sample_count; + corrected_dts += sample_duration * (uint64_t)sample_count; } - current_dts += sc->stts_data[i].duration * (int64_t)sample_count; + current_dts += sc->stts_data[i].duration * (uint64_t)sample_count; if (current_dts > corrected_dts) { int64_t drift = (current_dts - corrected_dts)/FFMAX(sample_count, 1);