From patchwork Mon Oct 18 09:40:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 31138 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp3092855ioa; Mon, 18 Oct 2021 02:41:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoVmQOppC06xVQBln3sYI5uEcXoVMPYYJTRYU66PVvD+Xabcz0AEjX32HwcnmWU6Dwf2Gd X-Received: by 2002:a05:6402:5114:: with SMTP id m20mr42406181edd.256.1634550074276; Mon, 18 Oct 2021 02:41:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634550074; cv=none; d=google.com; s=arc-20160816; b=HPJWrcGprfOxO6436TBWJV6ozGwmeJux1sLNemHt5rVXxBTaOrw8jDcElEF9ZCRMcl sbyERPHASEeTI6O6vxto5IhoWkLSzyXKU06isb9VtELrskZHSHC8JHHHvcLtS3mYy2y9 0BupFC/fhcnRcGNKjSJHEZjTV6JA6NczhGlxkycFpY0R+Smlc+Dm+AMHrrtPjEztSWu9 iYZZq4eI3wvQCYsox4QD6Sew+EnR1apxTXdIr1DA70gLHGEsbdVFNlwKdsB7AtGupIU6 5QC1zhKDCSMQC7NNN7nhDv5nQ5+z9jmj6dy4d2zmoDXFKpYuT+z0+3s94fRwIHchmeEu 29vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=HefuzkxKVUw4aFfAelM/YMfXDNJJ+kuSsTS7u6O2I34=; b=0h27zfABeK8ou8v2bMUt5R/Aa+/zn1bsGU+a8yAgMvS7zsrDLMQvQhJbz0iB3UgqOu 03Oz9PYzGt5h3Rv8COFGDclrNQCQxipUZYmDymB7tKjkv6XGoUb1NgEf2v47rEGb8Xf3 vWmRNTN8FkjkfBgjG1uA+Mbno0HvIYPAZKLxlRYxt1aD44ojsxFLOWjI083jr5AKSvTl 6+C4ZiOe76kjz4zmUsgAMA53eVCvyk1lnms1DIbKz6pLPda0qNNlUYVRyCpd2ePalK+L xK0WvmByVG4v+AjNbeuvQ/G/IbMHWAcfE5y+SZlheMtjmwpRs8k2aS6KUa4rEfI6r/0b dUng== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20210112.gappssmtp.com header.s=20210112 header.b=gzy0tTd6; 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 h7si29745820edb.295.2021.10.18.02.41.13; Mon, 18 Oct 2021 02:41:14 -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=@martin-st.20210112.gappssmtp.com header.s=20210112 header.b=gzy0tTd6; 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 7140D68A36E; Mon, 18 Oct 2021 12:41:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB7096805B6 for ; Mon, 18 Oct 2021 12:41:01 +0300 (EEST) Received: by mail-lj1-f169.google.com with SMTP id l5so7864078lja.13 for ; Mon, 18 Oct 2021 02:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VFwC7jPwi3Haw5LhrbolshJE+XiVatSRbW3MM8QFLec=; b=gzy0tTd6/q2Ys/aoOS8VNBUrUyJvj6ukAzVCEBMN1Dd8Rfwm25xp6XoszrFd6nDpHK 9eir5iEF6Rlht3io9UuoELhmpOzD7A/6Fggb3JR1jvkMkK2GERvFvZEq0UlDJnx65tra u6BgkwF0EKPgMceMvohTv/Sv3NDW+pia/Kei9E5HhjfvyweG7EUDJfuE7URpE7F6Ek5q M1ahoFFDXvm5JDwzlRiEp657DbcT0SAYgzNEVgEir+/LmDpxgFRAbHGr5aHZ8UpbkIqu ebYDetbWAHSgIOYX5KSsQ+MJMPFC+J/CkfLnUAitZfLwY6XmRVxhiZWmC4JbMEhUmUlK RmQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VFwC7jPwi3Haw5LhrbolshJE+XiVatSRbW3MM8QFLec=; b=wiVf55QwItMoII14qp5BWSPUIt9E0DLOoZQc0zi19tlcs3pl3ZbQJBEp6nlQK3ozv/ ItId3CM0K1THDFGxPQyQX80ULEw+IpM5ErytLuBGf43nx0Ze3raYcAEmLPAzSni5iDj6 itA4IVaPgieOeFtOKXdmVoCKWAmU1ms4br7r5CIba9LSG9ptT+J+07079qiloWaxfmzW +JXS1ViEuO94gC9KZZQE1byId9lGBvvN5wACsuI/sAL9uQpRbN/wxozvy/GujHk1O5rp 4Mhc12LJnjc7oMYpD8FMIPS+/fpS3i+en3VM1STuV1/n9gtXLmdIFidJtstAzHMm7Mxt vd7Q== X-Gm-Message-State: AOAM530wBYiTeIChoKfTybG0yrdkyR5uu4aWp+RiLkDRY6RZv0lm5YWP YF1SozRqn8GONbD/3bKQXwjMTxN8iv5Udasj X-Received: by 2002:a2e:90cf:: with SMTP id o15mr31246597ljg.241.1634550057770; Mon, 18 Oct 2021 02:40:57 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id i184sm329010lji.5.2021.10.18.02.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 02:40:57 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 Oct 2021 12:40:56 +0300 Message-Id: <20211018094056.3979756-1-martin@martin.st> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] seek: Fix crashes in ff_seek_frame_binary if built with latest Clang 14 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 Cc: =?utf-8?q?Martin_Storsj=C3=B6?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: oF0nXrVvUZC9 Passing an uninitialized variable as argument to a function is undefined behaviour (UB). The compiler can assume that UB does not happen. Hence, the compiler can assume that the variables are never uninitialized when passed as argument, which means that the codepaths that initializes them must be taken. In ff_seek_frame_binary, this means that the compiler can assume that the codepaths that initialize pos_min and pos_max are taken, which means that the conditions "if (sti->index_entries)" and "if (index >= 0)" can be optimized out. Current Clang git versions (upcoming Clang 14) enabled an optimization that does this, which broke the current version of this function (which intentionally left the variables uninitialized, but silencing warnings about being uninitialized). See [1] for discussion on the matter. [1] https://reviews.llvm.org/D105169#3069555 Signed-off-by: Martin Storsjö --- libavformat/seek.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/seek.c b/libavformat/seek.c index 40169736df..405ca316b3 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -283,7 +283,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags) { const AVInputFormat *const avif = s->iformat; - int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; + int64_t pos_min = 0, pos_max = 0, pos, pos_limit; int64_t ts_min, ts_max, ts; int index; int64_t ret;