From patchwork Mon Feb 20 19:29:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 40451 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp2166378pzk; Mon, 20 Feb 2023 11:29:44 -0800 (PST) X-Google-Smtp-Source: AK7set9VDbET6JTOVBy6tA1QULL8TbkJUYyEt47t/mw6IpHcK3mFdVZ/VsnBr6eyLz6sCE+sqT9J X-Received: by 2002:a17:906:8315:b0:88d:3c85:4ccf with SMTP id j21-20020a170906831500b0088d3c854ccfmr7727575ejx.25.1676921384640; Mon, 20 Feb 2023 11:29:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676921384; cv=none; d=google.com; s=arc-20160816; b=aK4HL8zpkpFG5xa5EmuRJX3X8/HIAgfMtjat5BQsr3V94N9aRBaoYVClj7OJJwe2Fb X+AnRb/srgiTXXa+85IrFrWzFD9mo5gaEBtIMLRkFeB8jzaaERalD9pE6B+CmOSY6BTQ zcFXQO/RxfmB0uOqc1Njean/DJZbrU+ODD78WMiV07PZp6aB8rptH9xRchGgN++g28d5 ktxUZBG3YoDmusjO3C3nk21YxBqH/VKxRN4fhxcNVS7fo1i4cGsr90VrY5XwGFY0/7jB s1C7cYXlgYdB77oWrx25jWHrKwL7Bc9yz7DX29vnFBgTBi/DmQE6uPypeb7lYvn/HKxa uZ7A== 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; bh=q3v5GJwUhU2qQltKNUE1lAWToZumMAaXkmk/dYj1G1Q=; b=HR0Tm5JMOYS7N7Ek2DO680jEy2M89mTrfA1aX8c7JLli54a4jIKMze26wUkjB4HcIN ybBsr6ItDLTnzEEg58l48nwaD/p0r3uG83jiP+g3kZ68fl+ZUVe1MKoU0WXYbCVWvyCe VjKbMzrO4HNhMdhsMdnBLs+CnoQKIhcO6sLaXvLOecFOXi8xc0pgaDlMqbq1tNJtFoKg NUSeqad3pjZhU5CXgwAzyBsUxV9XQQmoD/uojDGAMJQylkUtpNe+wysLsWK6wg9WUfTZ 3k6t/UVETdkL8yrTNjTkVwsrB/h+HQl1RtqKTrpOjK6GbZ2S7/TDr+4rfxrIqsoFFlkp 4T6g== 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 w8-20020a170906968800b008d67b53a661si3021204ejx.164.2023.02.20.11.29.44; Mon, 20 Feb 2023 11:29:44 -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 95A0E68BE74; Mon, 20 Feb 2023 21:29:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2B6A868BFEC for ; Mon, 20 Feb 2023 21:29:33 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id CD97260005 for ; Mon, 20 Feb 2023 19:29:31 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 20 Feb 2023 20:29:24 +0100 Message-Id: <20230220192929.4493-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/6] avformat/mov: Check samplesize and offset to avoid integer overflow 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: BRratAhuwYAq Fixes: signed integer overflow: 9223372036854775584 + 536870912 cannot be represented in type 'long' Fixes: 55844/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-510613920664780 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 6ab43b00c6..8af564ed61 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4192,6 +4192,13 @@ static void mov_build_index(MOVContext *mov, AVStream *st) if (keyframe) distance = 0; sample_size = sc->stsz_sample_size > 0 ? sc->stsz_sample_size : sc->sample_sizes[current_sample]; + if (current_offset > INT64_MAX - sample_size) { + av_log(mov->fc, AV_LOG_ERROR, "Current offset %"PRId64" or sample size %u is too large\n", + current_offset, + sample_size); + return; + } + if (sc->pseudo_stream_id == -1 || sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) { AVIndexEntry *e;