From patchwork Thu Sep 2 09:19:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Lhomme X-Patchwork-Id: 29948 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp97326iov; Thu, 2 Sep 2021 02:19:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxwHtseUcfZ0+D1axvOGHNfZFRFIUa6wGVYRXZnODBjDHG3s5OXfQnGYBBzJNGJzPYpQvN X-Received: by 2002:a17:906:da01:: with SMTP id fi1mr2658518ejb.149.1630574352680; Thu, 02 Sep 2021 02:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630574352; cv=none; d=google.com; s=arc-20160816; b=BLZcbTP3+IbrSu5pmW+2Cj4uNDf4tZZmKXB0RI3dWLfJHNTGACcTCszJCuWmM4sFbG 3FLGbZh3Seoc3mkV3nOU1/+tge9SemaHFsoUA9iiVd7KFXuOYNzJDM0nNRsXXNk1BTz0 bqRqmo72AP4dJsoiPqFziLvdWB4PfMMIb5KEJjBIO+mepZ3p1rFbcsuK5EEnTzKESGUw q+jxwHgKpLgOeDQDTH4jO4ehUcGETDNo41bVt2iuIBnk8g9icOFSSIijyIsPrfGDRoe8 c9aYAT8zwjthpRs7y6a+uj8ZmQuABiIfkI4OjxR4LZSsQYtFqgTcBJizqH2jhhlVs/Kt QLWQ== 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 :delivered-to; bh=rU+Weolf9tLkwpVGo+BPevA337vPaIIcG8anoL8o1Jk=; b=0yvOUiMTYrwgnQCJl8pGb1Yzf0BEkIqAICx7hzh+GV32/BHRBRLwl29xfQtckud2Z7 3DGivAtku9bfY1KW5tYLIqB5sjnoiUk+9YZbYJSXyJ5o+9ZtR5r1qcUJWZTRIAIdJvZD K/yGU8ge+GVzFx0jr1IueXPjGZnJ/o5fQm7tAdJPjNl4KtNi3RoUhPQbfiZvsTBCkyc1 Cl2fL6zC/l7ESQOyEDkPeLnun9O4RS9vnqGZiwZyYg7KWkJiWSyG+NdSci9G2SYysEcR fTlpCe46noIeUU6/F8f2JSw1tpyynHbv6tOzfrxY6DVRaq+YtMEOezK9GslDwwCVOn4i piUQ== 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 o2si1490537ejy.80.2021.09.02.02.19.11; Thu, 02 Sep 2021 02:19:12 -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 6383668A2DE; Thu, 2 Sep 2021 12:19:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 74D6668991B for ; Thu, 2 Sep 2021 12:19:01 +0300 (EEST) Received: from smtp102.mailbox.org (smtp102.mailbox.org [80.241.60.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4H0b2r5gFMzQk71 for ; Thu, 2 Sep 2021 11:19:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de From: Steve Lhomme To: ffmpeg-devel@ffmpeg.org Date: Thu, 2 Sep 2021 11:19:10 +0200 Message-Id: <20210902091910.13300-1-robux4@ycbcr.xyz> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0B71026D Subject: [FFmpeg-devel] [PATCH v2] avcodec/vp9: avoid using uninitialized mutex/condition 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: uVF7P2ISZTAX When using slice decoding vp9_free_entries() is called before vp9_alloc_entries() is ever called. It should destroy properly initialized variables (or check it was never called before). It usually works undetected as pthread implementations allows NULL as a special value (and should return EINVAL but doesn't). But pthreadGC2 doesn't allow NULL in pthread_mutex_destroy() and crashes when that's the case. --- libavcodec/vp9.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 874005a5ae..8a3d82da09 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -42,7 +42,7 @@ static void vp9_free_entries(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; - if (avctx->active_thread_type & FF_THREAD_SLICE) { + if (avctx->active_thread_type & FF_THREAD_SLICE) { pthread_mutex_destroy(&s->progress_mutex); pthread_cond_destroy(&s->progress_cond); av_freep(&s->entries); @@ -1796,6 +1796,10 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) s->last_bpp = 0; s->s.h.filter.sharpness = -1; + if (avctx->active_thread_type & FF_THREAD_SLICE) { + pthread_mutex_init(&s->progress_mutex, NULL); + pthread_cond_init(&s->progress_cond, NULL); + } for (int i = 0; i < 3; i++) { s->s.frames[i].tf.f = av_frame_alloc();