From patchwork Wed Mar 10 01:05:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26290 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 48A4B448EE5 for ; Wed, 10 Mar 2021 03:06:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 203B268A73D; Wed, 10 Mar 2021 03:06:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BE69687F3D for ; Wed, 10 Mar 2021 03:06:16 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id ox4so18058417ejb.11 for ; Tue, 09 Mar 2021 17:06:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:reply-to:mime-version :content-transfer-encoding; bh=Fh0QGVNgQ+KXSWZBUEwmj8CSK5xbFDaxo1OKAP4Mg6s=; b=M0/DYRGqfOhXApBO4NlaDChHtRmE02cYj2T7j4bANMi/NWP3D3g5wmJoaR0lEs7kQG WrsaOvOPug8n/cirUMvDC6Y9tIYA96VM06Rx0pX00o+rW9Kono4YJzqYeOb4z99zVQYT CA+Mvt/1QkpFL0LCNVKTFJ5UsQ9cZyHTxYAxvoouyDPPzaH10y06pJtpPHIHWd/c5Dh8 ujq/JGtxpru1oCqYIQU5wtJx1oIYixtcR+QBHI6qrZ7Gsvzz+BKA1KhdHvRGYGbDojwe XjiwVeL0E5V8MBPFk3nsexu0fBbTlL5RSzir0wnrHay5Q9QU2TY2DOM5tNcqJIrtwapb WHIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :mime-version:content-transfer-encoding; bh=Fh0QGVNgQ+KXSWZBUEwmj8CSK5xbFDaxo1OKAP4Mg6s=; b=MgSvNTzytQliqPYUVwic6gI8EzDTempXbpfo+Fcsc3FiHdmuo1uySYV/LnokSVB4qa 4pQYLyeWZ8ZbttSCK3Dnm2MUTgrk5R/JPAIZ7KJaYyonZZJrxipd3Z+aCgcvRwoOhwkp 3oY3cLOxne0z+mqPuK2OJkL5ht/jApCTFArKvpL3+WhnMmdQ3W4qXx4oF0jXLhy5x1Z2 FlvSVpjfWjwMmYeKr+picOnMQnrzrBGM7jAYQuoib3rH2YPI0YUQa3zWQbD/QavarYMM YjME6bAaXcEjYuU2MxBn3trzqurZjEHZyoF1eSpnXtopR9tzeRE/L5JdVb8VatYe8WZI lA4g== X-Gm-Message-State: AOAM532X+SfmWV78tbPREi3DDC88EOwaDLbNqh4Fnsv477Z5KK146Ncp qtzjZjMO3WGpKSzAa4MFzxFb4iG2CYY= X-Google-Smtp-Source: ABdhPJzTi6vfqv7ANjeZ50efBFNAg4S4u0xZtBzON1GHmtu7cEz+FyrnjhDb+3Z/QkU7O6BIt3iw1A== X-Received: by 2002:a17:906:9515:: with SMTP id u21mr870020ejx.86.1615338375590; Tue, 09 Mar 2021 17:06:15 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:15 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:05:54 +0100 Message-Id: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/8] avcodec/cbs: Remove redundant checks for CodedBitstreamContext.codec 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Setting this field happens immediately after the allocation in ff_cbs_init(), so the whole CBS code may presume that any CodedBitstreamContext has this set. Lots of code already presumed this, yet ff_cbs_close() did it inconsistently: It checked before checking whether the CodedBitstreamType has a close function; yet it simply unconditionally read ctx->codec->priv_class. Coverity complained about this in issue #1473564, which this commit fixes. Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index ecf22b3fdb..c7f69845fb 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -94,7 +94,7 @@ int ff_cbs_init(CodedBitstreamContext **ctx_ptr, return AVERROR(ENOMEM); ctx->log_ctx = log_ctx; - ctx->codec = type; + ctx->codec = type; /* Must be before any error */ if (type->priv_data_size) { ctx->priv_data = av_mallocz(ctx->codec->priv_data_size); @@ -119,7 +119,7 @@ int ff_cbs_init(CodedBitstreamContext **ctx_ptr, void ff_cbs_flush(CodedBitstreamContext *ctx) { - if (ctx->codec && ctx->codec->flush) + if (ctx->codec->flush) ctx->codec->flush(ctx); } @@ -130,7 +130,7 @@ void ff_cbs_close(CodedBitstreamContext **ctx_ptr) if (!ctx) return; - if (ctx->codec && ctx->codec->close) + if (ctx->codec->close) ctx->codec->close(ctx); av_freep(&ctx->write_buffer); From patchwork Wed Mar 10 01:05:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26296 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0274F44B25E for ; Wed, 10 Mar 2021 03:14:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D17FC68A874; Wed, 10 Mar 2021 03:14:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18886689F02 for ; Wed, 10 Mar 2021 03:14:24 +0200 (EET) Received: by mail-lf1-f54.google.com with SMTP id u4so30601205lfs.0 for ; Tue, 09 Mar 2021 17:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=7uRfk8fSPB582+iTS9G8ZpTWnPeWy+3Q1DZBMMWfPMI=; b=cYuVtR5zkMbREs7S1QrZkDg6psKIi9JpFOaYe9Ees/0Esknz5mBtauugTUm/BA/9mA n6Bb/QKujmWsHaNyp96aFjhYTR79EWCMMrDVfv5Sllt9sGyhgtQnGmEvgR/wiCdY5Gyo 95QIqOC9YqumSsgNlPk3uAgzHFptJ29CIdvxk2MiWlEWLem1z9pkUM29rSQhOdhwtm9k HfFWLqO9WhQoUlP/FAQytgwlgVWDFJB67p6+BAN1QxtBtAal0JhqMXRZcFNh8gNcUB7W 808X3133rFoUI4cPy8xt/vheJNnKRuhWcT58VioKcYNwa26QEqIkv9bLNlYyGRPaXVoA E4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=7uRfk8fSPB582+iTS9G8ZpTWnPeWy+3Q1DZBMMWfPMI=; b=Oo10BwUGDW5WRQjxEOysD8bHdU/BAUcBWe0bC7W1tWCcibfm68pggCm6DVi45SZ0p8 A259NB3m0FFTmxrzMYvOa6nrDuoz4m9tEODzLBguizWQs7WWjKDueWTS1uXWCueOJ/LQ ANj9F31pX/oVUl8Ic5mAZOeHOfgMYVjvKIPVOXGJvd2KgNXFk/eap7kCLf7AMjE3mD6+ WJRJcD/dlCj2mdhVSNOIXaIZBK58faQy6cif+BCggOCK0l0dadHm+YliBL4iIeOF8c5U 10oeJTKNtQBIwkqw5qIAiP8ZF3ZlfnqTX8NuXsKurvsfHjPZnwTxw5dl9lKRORv5MLLa QR8g== X-Gm-Message-State: AOAM533Y9tpLzMB4ydC2N96QLmuxtEW2GSI0jHJAM/sT3rEzPVec8DOi 0qFqWrBGtFL7hDkT+79+4pw1osSK1fA= X-Google-Smtp-Source: ABdhPJwelvos4Cj/plwznhwTSZdrPIJcpOnfUCK0PCzkqzfTnw13PhD/8vxRfkHAo+KXp5++lxaihw== X-Received: by 2002:a17:906:a86:: with SMTP id y6mr852963ejf.354.1615338393678; Tue, 09 Mar 2021 17:06:33 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:33 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:05:55 +0100 Message-Id: <20210310010601.1142819-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] avcodec/h264_cavlc: Remove redundant check 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The only caller to ff_h264_decode_init_vlc() already uses ff_thread_once() for the call; ergo the check via a simple int with static storage duration in ff_h264_decode_init_vlc() is redundant. And if it were not redundant, it would be a potential for data races. So remove it. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_cavlc.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index 6481992e58..d0548d84f6 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -325,12 +325,8 @@ static av_cold void init_cavlc_level_tab(void){ } av_cold void ff_h264_decode_init_vlc(void){ - static int done = 0; - - if (!done) { int i; int offset; - done = 1; chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table; chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size; @@ -410,7 +406,6 @@ av_cold void ff_h264_decode_init_vlc(void){ INIT_VLC_USE_NEW_STATIC); init_cavlc_level_tab(); - } } static inline int get_level_prefix(GetBitContext *gb){ From patchwork Wed Mar 10 01:05:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26293 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4866844ACEC for ; Wed, 10 Mar 2021 03:13:02 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1B0A568A83B; Wed, 10 Mar 2021 03:13:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CC622689F02 for ; Wed, 10 Mar 2021 03:12:55 +0200 (EET) Received: by mail-lf1-f49.google.com with SMTP id u4so30596380lfs.0 for ; Tue, 09 Mar 2021 17:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=dyDNyzFL3xT6775L4ppLWg7ZZOfSqX/bQbewJq9Lcio=; b=I+Exyx/OyJPLEifG+HSUfuxgXqfh3f69WeI8KFmUwDfId82j1BfkX7hbHotCOr0u+D pQRK/aYz8JzpMdGE3/NzVolwxXKbxMPjo9GqfXaUJpehQHfAyhkVDabVhxDMTIhvRK3U 3nLumrUUglN4NCPT88jhGeYHHE5iFhXhbMTxGuu+/yiGnj5Zpea7a/RIKhNw/gBTLjDR KcfWbqFq8zXZbh7GXlgdesTYup02xTx9EYMtbKdhW+Gmdakj1nAAnM+6Ox02a5AlDf+a RW6LNO6Fx01UA3N63ch5x8auMo02t4QZRylZd76Ut0N7ymjhs7OmNk6KX+NEAc8UBUDo wzAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=dyDNyzFL3xT6775L4ppLWg7ZZOfSqX/bQbewJq9Lcio=; b=ZhEqaoESuZO+rPGmHL3OKIzc60QTgmHJs8E9HdIOBA0Vl6ZxUg0PRqEdpsIrtbfWBt jl6+sDgg5BAmB9FoOsgwabZGc2k1arP+ivQoQAZg91IJg9aJaEcYZEK2cw/Z417p1xAs cMMX7Q0+UWUaal0wxxdyjtp1D4cac7rCFIy63UXMZZ+r87LJbVBn7m0M0zBVt0lzPv/h kIs8Axsa0y0cuuKjKOyigahhrzwmSjaHRyg7tOyZcF9KDJdTafevHujb5XIAWyiiVesg Z+WU48IoascI9gE2PPxtlplxTCtd3RQhqaYqFLrt3pG4Z6rBl06iwKOL6FPg7+czgO34 J0+A== X-Gm-Message-State: AOAM5323vUtCIkKe0tWqHlEOyFVnu/Ghbnb9Wt1dxi02473ZpIukZijv h2VkdL9tBJ0V3m+P/sHl5GFL07s8rpU= X-Google-Smtp-Source: ABdhPJw2ckcXfhFg1s4VUnXN/lh1bGI8jScY1A1mHlsu0Q8dveCg36Kh1oiBHm3Ous+rcv3PO85JxQ== X-Received: by 2002:a05:6402:22f6:: with SMTP id dn22mr420964edb.214.1615338394386; Tue, 09 Mar 2021 17:06:34 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:34 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:05:56 +0100 Message-Id: <20210310010601.1142819-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/8] avcodec/h264_cavlc: Reindent after the previous commit 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_cavlc.c | 152 ++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index d0548d84f6..9f5f692331 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -324,88 +324,88 @@ static av_cold void init_cavlc_level_tab(void){ } } -av_cold void ff_h264_decode_init_vlc(void){ - int i; - int offset; - - chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table; - chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size; - init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5, - &chroma_dc_coeff_token_len [0], 1, 1, - &chroma_dc_coeff_token_bits[0], 1, 1, +av_cold void ff_h264_decode_init_vlc(void) +{ + int offset; + + chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table; + chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size; + init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5, + &chroma_dc_coeff_token_len [0], 1, 1, + &chroma_dc_coeff_token_bits[0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + + chroma422_dc_coeff_token_vlc.table = chroma422_dc_coeff_token_vlc_table; + chroma422_dc_coeff_token_vlc.table_allocated = chroma422_dc_coeff_token_vlc_table_size; + init_vlc(&chroma422_dc_coeff_token_vlc, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4*9, + &chroma422_dc_coeff_token_len [0], 1, 1, + &chroma422_dc_coeff_token_bits[0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + + offset = 0; + for (int i = 0; i < 4; i++) { + coeff_token_vlc[i].table = coeff_token_vlc_tables + offset; + coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i]; + init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17, + &coeff_token_len [i][0], 1, 1, + &coeff_token_bits[i][0], 1, 1, INIT_VLC_USE_NEW_STATIC); - - chroma422_dc_coeff_token_vlc.table = chroma422_dc_coeff_token_vlc_table; - chroma422_dc_coeff_token_vlc.table_allocated = chroma422_dc_coeff_token_vlc_table_size; - init_vlc(&chroma422_dc_coeff_token_vlc, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4*9, - &chroma422_dc_coeff_token_len [0], 1, 1, - &chroma422_dc_coeff_token_bits[0], 1, 1, + offset += coeff_token_vlc_tables_size[i]; + } + /* + * This is a one time safety check to make sure that + * the packed static coeff_token_vlc table sizes + * were initialized correctly. + */ + av_assert0(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables)); + + for (int i = 0; i < 3; i++) { + chroma_dc_total_zeros_vlc[i + 1].table = chroma_dc_total_zeros_vlc_tables[i]; + chroma_dc_total_zeros_vlc[i + 1].table_allocated = chroma_dc_total_zeros_vlc_tables_size; + init_vlc(&chroma_dc_total_zeros_vlc[i + 1], + CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4, + &chroma_dc_total_zeros_len [i][0], 1, 1, + &chroma_dc_total_zeros_bits[i][0], 1, 1, INIT_VLC_USE_NEW_STATIC); + } - offset = 0; - for(i=0; i<4; i++){ - coeff_token_vlc[i].table = coeff_token_vlc_tables+offset; - coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i]; - init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17, - &coeff_token_len [i][0], 1, 1, - &coeff_token_bits[i][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - offset += coeff_token_vlc_tables_size[i]; - } - /* - * This is a one time safety check to make sure that - * the packed static coeff_token_vlc table sizes - * were initialized correctly. - */ - av_assert0(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables)); - - for(i=0; i<3; i++){ - chroma_dc_total_zeros_vlc[i+1].table = chroma_dc_total_zeros_vlc_tables[i]; - chroma_dc_total_zeros_vlc[i+1].table_allocated = chroma_dc_total_zeros_vlc_tables_size; - init_vlc(&chroma_dc_total_zeros_vlc[i+1], - CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4, - &chroma_dc_total_zeros_len [i][0], 1, 1, - &chroma_dc_total_zeros_bits[i][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - } - - for(i=0; i<7; i++){ - chroma422_dc_total_zeros_vlc[i+1].table = chroma422_dc_total_zeros_vlc_tables[i]; - chroma422_dc_total_zeros_vlc[i+1].table_allocated = chroma422_dc_total_zeros_vlc_tables_size; - init_vlc(&chroma422_dc_total_zeros_vlc[i+1], - CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8, - &chroma422_dc_total_zeros_len [i][0], 1, 1, - &chroma422_dc_total_zeros_bits[i][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - } - - for(i=0; i<15; i++){ - total_zeros_vlc[i+1].table = total_zeros_vlc_tables[i]; - total_zeros_vlc[i+1].table_allocated = total_zeros_vlc_tables_size; - init_vlc(&total_zeros_vlc[i+1], - TOTAL_ZEROS_VLC_BITS, 16, - &total_zeros_len [i][0], 1, 1, - &total_zeros_bits[i][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - } + for (int i = 0; i < 7; i++) { + chroma422_dc_total_zeros_vlc[i + 1].table = chroma422_dc_total_zeros_vlc_tables[i]; + chroma422_dc_total_zeros_vlc[i + 1].table_allocated = chroma422_dc_total_zeros_vlc_tables_size; + init_vlc(&chroma422_dc_total_zeros_vlc[i + 1], + CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8, + &chroma422_dc_total_zeros_len [i][0], 1, 1, + &chroma422_dc_total_zeros_bits[i][0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + } - for(i=0; i<6; i++){ - run_vlc[i+1].table = run_vlc_tables[i]; - run_vlc[i+1].table_allocated = run_vlc_tables_size; - init_vlc(&run_vlc[i+1], - RUN_VLC_BITS, 7, - &run_len [i][0], 1, 1, - &run_bits[i][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - } - run7_vlc.table = run7_vlc_table, - run7_vlc.table_allocated = run7_vlc_table_size; - init_vlc(&run7_vlc, RUN7_VLC_BITS, 16, - &run_len [6][0], 1, 1, - &run_bits[6][0], 1, 1, + for (int i = 0; i < 15; i++) { + total_zeros_vlc[i + 1].table = total_zeros_vlc_tables[i]; + total_zeros_vlc[i + 1].table_allocated = total_zeros_vlc_tables_size; + init_vlc(&total_zeros_vlc[i + 1], + TOTAL_ZEROS_VLC_BITS, 16, + &total_zeros_len [i][0], 1, 1, + &total_zeros_bits[i][0], 1, 1, INIT_VLC_USE_NEW_STATIC); + } - init_cavlc_level_tab(); + for (int i = 0; i < 6; i++) { + run_vlc[i + 1].table = run_vlc_tables[i]; + run_vlc[i + 1].table_allocated = run_vlc_tables_size; + init_vlc(&run_vlc[i + 1], + RUN_VLC_BITS, 7, + &run_len [i][0], 1, 1, + &run_bits[i][0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + } + run7_vlc.table = run7_vlc_table; + run7_vlc.table_allocated = run7_vlc_table_size; + init_vlc(&run7_vlc, RUN7_VLC_BITS, 16, + &run_len [6][0], 1, 1, + &run_bits[6][0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + + init_cavlc_level_tab(); } static inline int get_level_prefix(GetBitContext *gb){ From patchwork Wed Mar 10 01:05:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26297 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 96B0644B4D6 for ; Wed, 10 Mar 2021 03:34:27 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A17A68A862; Wed, 10 Mar 2021 03:34:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 110DD687FE1 for ; Wed, 10 Mar 2021 03:34:21 +0200 (EET) Received: by mail-lf1-f47.google.com with SMTP id v9so30650164lfa.1 for ; Tue, 09 Mar 2021 17:34:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=zOIevLeFWMeCaI4BwvAmYpB7S4SVawKFX/6TB3vfLnc=; b=RSXE6aO1F/3h/m0oDJpmyD8k8hWRowfgzblh6AX5Dx18tJxnucPY1lXxT7qsevgCS9 o3KYmPQSdCqpHk2PnTzTwhOvB6/mjT9l9h5cNLSAzgNISzUXjoh9MmfydOojIL59Bgm9 Z2gtD1W7iQGXqPxTAYVOilA8KdNfAt2ijc/WTjrYPiERBeykkQLW3S0u1+dhAkG4dcZA XSJNCdngxc36OTG3WutuGYQgydVd1nKGdBcITzEo+g080EBkLBFjCA6/MCT2Vjdlw9iA bjX3Y3MUycrPF1IslZQHiyCDB74kr/Tv4ThYVUzxU07sUU4oLrggTQbDkuQGtw/JB2bS MOBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=zOIevLeFWMeCaI4BwvAmYpB7S4SVawKFX/6TB3vfLnc=; b=YzT3FcWCpaAtP+oIObkW7T/i8frO6xwE64g58F1LvwvpRl/1LynT4jxDWX8tFrnGBK dxBvBUhVts5/AlGGVAc8UaDBjoGrNd/mOIgnC1Vwl1hl21QR784qM0Dfg92hI4ltcex3 Nc7vrD65tD9bAk9UPEEqfNQpfUHy3M9gCn1Lh7v0y05FaDcIyMCttZV9o1jRjdr3r1oO tObnrZRHQjvNzLDE1IaP43TaMF1zS+C7OZqgKF2+1qajtMQWfmmtaKjMF+PThPGj8afA 4VrsSEmKjp9ecDDiCtNkl7qyJLVjKIxlcdoLssa0MYdYNlOTSbsw83/61mjSHvdv2b2K 2YEw== X-Gm-Message-State: AOAM533I8Bi3RnVgjhEAEvCFuo5pj+mmJSXRMaLn5jk+ZyUKyUTK8pt7 OsZBwc5BgH4giUJvlZpqORVg2sdKuso= X-Google-Smtp-Source: ABdhPJzdvCHbHHRPUdV7VZdk8XLpcr0EDZFcyPu5E3XMSHjo7Hop4+siG4qY76Agyq/8cWdXPksaBA== X-Received: by 2002:a17:907:2075:: with SMTP id qp21mr805673ejb.451.1615338395013; Tue, 09 Mar 2021 17:06:35 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:34 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:05:57 +0100 Message-Id: <20210310010601.1142819-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/8] avutil/avstring: Limit string length in av_escape to range of int 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Otherwise the caller can't distinguish the return value from an error. Signed-off-by: Andreas Rheinhardt --- libavutil/avstring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/avstring.c b/libavutil/avstring.c index e33d4aac51..832bec750f 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -337,7 +337,7 @@ int av_escape(char **dst, const char *src, const char *special_chars, { AVBPrint dstbuf; - av_bprint_init(&dstbuf, 1, AV_BPRINT_SIZE_UNLIMITED); + av_bprint_init(&dstbuf, 1, INT_MAX); /* (int)dstbuf.len must be >= 0 */ av_bprint_escape(&dstbuf, src, special_chars, mode, flags); if (!av_bprint_is_complete(&dstbuf)) { From patchwork Wed Mar 10 01:05:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26291 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 68905448EE5 for ; Wed, 10 Mar 2021 03:06:43 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4ADDF68A830; Wed, 10 Mar 2021 03:06:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7376068A315 for ; Wed, 10 Mar 2021 03:06:36 +0200 (EET) Received: by mail-ed1-f42.google.com with SMTP id w9so24409543edt.13 for ; Tue, 09 Mar 2021 17:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=4AwLu1n/V789jvqPfEnpUrPmE032pwnWyS/aNRI5R+A=; b=ranz/xJ3kVnbn0LPOTjj2TY4r3dEhTS20S4yc1rLh+TYt0ncMiITWwN/Pq4lrFLsX2 JY9MkCkrt8KHY9uXGyG5W/kieIRlXzhBlg3XmxFYotcidnGR4ToqcwkK+gwDpsrvGIH7 mL8Q4NtMutYWipNYcg8W2saDrs4gzxQZN6IewUt5+916yPdwBVWviVS84VSzFau9e8Kl lCQuMOewz1Sy/35iaTC6SgcCobGHAIeHv9wLeT1BErMtgME61uskG2gKyFF9E4JQuC1o RWn+nNd+ef8/NaoAKD8K5qxjv5jo5dW0DZQanv1W737qpi3YsIGc+WMULOgwKlIKTzOr 7DmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=4AwLu1n/V789jvqPfEnpUrPmE032pwnWyS/aNRI5R+A=; b=g+R0fJssTsCG/8iRrpBNrFo+RzKZMSBkdPksyNL4g9Ae7c1KKeFPeAZGxwWJljIa+a 9ZadlJulAkY+pRrAxj2jXiXmfVE6btxhwBTrUU6Q0sTv3za0ZXtXiAhrw8fMrjJyiAhD v4x3Vj/ioVigbViQhMmd80WypQFelh3l2YqXJDuc2xGnn8JRlTX8QDQlXva0UZGwpXMl 9W2GUZQn4bxTSxzupQIjcoJGhJSm/03oab+UFSj/aNXio2qETBSQ49FxhV2B2+GYSI+f zY2l4bhn19WL391c6auSvGTqgQyGngLvUq/KCZ9MlhOEPzEf93tGV7L/f3XdU77BCwWV ZIyQ== X-Gm-Message-State: AOAM530oq3Ddb3NFez8ZuX36UhRIFFNtdCvoTQqLZCtfU4IiO0YxSSdl ulakpoxxwT/2YDDh4u6nVw79NCp7z9M= X-Google-Smtp-Source: ABdhPJy+v6yG/Xd1nR+SYbcfHS3bE5SWLBBZiD7ROGiqcgrZasfhGLHk8267HYjcazFrm2fSNFGmMg== X-Received: by 2002:a50:ee18:: with SMTP id g24mr389856eds.267.1615338395697; Tue, 09 Mar 2021 17:06:35 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:35 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:05:58 +0100 Message-Id: <20210310010601.1142819-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/8] avutil/avstring: Check for memory allocation error in av_escape 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" av_bprint_finalize() can still fail even when it has been checked that the AVBPrint is currently complete: Namely if the string was so short that it fit into the AVBPrint's internal buffer. Signed-off-by: Andreas Rheinhardt --- libavutil/avstring.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavutil/avstring.c b/libavutil/avstring.c index 832bec750f..49e8df55aa 100644 --- a/libavutil/avstring.c +++ b/libavutil/avstring.c @@ -336,6 +336,7 @@ int av_escape(char **dst, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags) { AVBPrint dstbuf; + int ret; av_bprint_init(&dstbuf, 1, INT_MAX); /* (int)dstbuf.len must be >= 0 */ av_bprint_escape(&dstbuf, src, special_chars, mode, flags); @@ -343,10 +344,10 @@ int av_escape(char **dst, const char *src, const char *special_chars, if (!av_bprint_is_complete(&dstbuf)) { av_bprint_finalize(&dstbuf, NULL); return AVERROR(ENOMEM); - } else { - av_bprint_finalize(&dstbuf, dst); - return dstbuf.len; } + if ((ret = av_bprint_finalize(&dstbuf, dst)) < 0) + return ret; + return dstbuf.len; } int av_match_name(const char *name, const char *names) From patchwork Wed Mar 10 01:05:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26295 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id CF50944ACEC for ; Wed, 10 Mar 2021 03:13:26 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B1D7768A89C; Wed, 10 Mar 2021 03:13:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9D41868A846 for ; Wed, 10 Mar 2021 03:13:20 +0200 (EET) Received: by mail-lj1-f178.google.com with SMTP id m11so23281043lji.10 for ; Tue, 09 Mar 2021 17:13:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=MFQQG5l0hHv8sMIeUuInODJ6XdS4JPxSHSkM8IqL2PI=; b=hcGgpkh5xTDU6vY3r1Q79RH0KAD3G5WdI7LlSu91LqlwoBDBG1myOpugiek1fYAqX+ 0iWpiqOr6OTpeRDxTilK82PQJYVwETpsFJ50t7Kdc3/mzODNMLkMFF/1f2MZ8O6Ritxs UnLHYYKM4nzgLA+jIall7Im9zBVUicl+u2bU81vcLS+7Qch7PU5hwHKow3HWwYQtR9NW h7UkrARjvfJZFNbifdjhiMahj88saQY2bfaj31dZ/gtlaO1abWZjv7QBvDkznK7bGTss tzLLJWfx7f5reBDakb2AQDgOBCpsQxEO8LPdeum42JyWfSBU+9g5G+JFbXaADT+/8oRL eyIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=MFQQG5l0hHv8sMIeUuInODJ6XdS4JPxSHSkM8IqL2PI=; b=GuqTYbmxqro+AkyIRYiLYoxzH/nWR0ET0IZXeQLE+3jfmCTpPCAnOnzp8rs/Tz8VJ6 bG3J1bzcxOkVsct2SN+Z6Mey3upxjhAnD8GKI4QQMgZJ+CbcgkfhBgNSa6oLrVYpYeWs MhUmxEwVY/GxpXwZCtxcRzh+Z2Kyohj2WIJ+QjSOkZGYp6tpNsZ3bchbPt2Y9ukggJQE 8/RwvFRjxmcLiMm3Ae52I4iYcLns0I217rFVKw3s/HJKpqQTMOEus5PUm3W9a8PAUX7G WiOWjRNjex9xBd+cPCNsut/4YRD86xyChcJiZr82v1uTfN7Q4DAihCMzBJoWE4Nn02lm 1x9Q== X-Gm-Message-State: AOAM533sR9B30PNCPN70MNXTN/viIozE+VlQDRECwtA5Qf5c4WVyyn6Q GOtnq71BgK1nqjZN0N6lArET61rSvlI= X-Google-Smtp-Source: ABdhPJyBNYmgCTU0IHwkAtPhz3nNB3zREsc/6hM5DpXVf3IXu//X8wyjJukyCn1q3fc19OrN9caW6w== X-Received: by 2002:a17:907:75c2:: with SMTP id jl2mr849334ejc.334.1615338396332; Tue, 09 Mar 2021 17:06:36 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:36 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:05:59 +0100 Message-Id: <20210310010601.1142819-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/8] avcodec/cbs_sei: Don't use -1th element of array 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" (This affected only suffix SEI messages; yet no such SEI messages are currently inserted.) Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_sei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/cbs_sei.c b/libavcodec/cbs_sei.c index c49830ad77..2a96db9674 100644 --- a/libavcodec/cbs_sei.c +++ b/libavcodec/cbs_sei.c @@ -166,7 +166,7 @@ static int cbs_sei_get_unit(CodedBitstreamContext *ctx, } if (i < 0) { // No VCL units; just put it at the end. - position = -1; + position = au->nb_units; } else { position = i + 1; } From patchwork Wed Mar 10 01:06:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26294 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A04A744ACEC for ; Wed, 10 Mar 2021 03:13:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 869FC68A880; Wed, 10 Mar 2021 03:13:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D105D68A67E for ; Wed, 10 Mar 2021 03:12:58 +0200 (EET) Received: by mail-ed1-f53.google.com with SMTP id b13so24595085edx.1 for ; Tue, 09 Mar 2021 17:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=3Xds82XBid8NfNcR6pxWY8maCIw2eIjioyGR4CCqFjs=; b=QsSycvCvvQAZ9jqgqWTfNS1QmwkYPIs8A/rTYl/SfJ027UInHI+ZBz/NLwcVnAWNWe ck8+2Gj1hT5WzymQwa1s8MSsNh2pt9If90xbqEyT8VmjCZgAHjLjrK8mp+P0mVzgkVpe lqMOAzDaUEC2Tp1ry4f1t1Og7k3WB+tE8hfOATWrDfBjl0I/7PHcxajjbUwd9zBTZzmK LyMFsnb3zxXvgoBmxI+vzKQ51tZ+R18K14feyFRfplRiQz94olg5609gnBXw4pREYccl 4cgeLOXYqPnaM8KAzj05XbMjAwvegSPJ3DmfGQC+DA8VGtwgK3JnJsHJ7qLnOItFMqbN E3dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=3Xds82XBid8NfNcR6pxWY8maCIw2eIjioyGR4CCqFjs=; b=h39C9Fri96dZMywuxEpb42Xd/fhTer3yZ5TH3A1qzMrWXohF/ELa0PmtxkkgEzf58o TMFDLbwWZ6VLOvjSKSgTEA6j/lnzrt+00UBz5rATmKitQ7jkNEqveh269Ei2no1efLrN RMrogG+94Aav41xYbc9/XZ5h+hRNNlAvCTL7fY+8YVs70vNv86xG9/Xbb12RrRZKU5DL z3A9onPFeLXsyyMl7UlozZ8OcJ4c2fKGPzlyai1JONd5oItTV+tVapOht9VaxhgNl5nz iXrNfImIUzFemwr076lHjs+A5+b9WnfpUHahs5zSeKW9OsIbwrj2/DiQordDi5iJxQRu Zs9Q== X-Gm-Message-State: AOAM532FmHoK9hUPCcBZu74UfKA728AqnCReP1zn7BeMnOE5vpOindYt nDoAMw2MpZHwbXC/GaRai1vI2aBfrBs= X-Google-Smtp-Source: ABdhPJzv/R7pvTRkNDOUmFopVVlc2Eq0xcE4ttTvVoXRbdqcV4Vab0RSR6OmFE/3ZrMtDaVIORSPxQ== X-Received: by 2002:a17:906:7384:: with SMTP id f4mr853058ejl.196.1615338397196; Tue, 09 Mar 2021 17:06:37 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:36 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:06:00 +0100 Message-Id: <20210310010601.1142819-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/8] avcodec/cbs_sei: Fix leak of AVBufferRef on error 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" An AVBufferRef (and the corresponding AVBuffer and the underlying actual buffer) would leak in ff_cbs_sei_add_message() on error in case an error happened after its creation and before it has been attached to more permanent storage. Fix this by only creating the AVBufferRef immediately before attaching it to its intended target position. (Given that no SEI message currently created is refcounted, the above can't happen at the moment. But Coverity already nevertheless noticed: This commit fixes Coverity issue #1473521.) Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_sei.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/cbs_sei.c b/libavcodec/cbs_sei.c index 2a96db9674..141e97ec58 100644 --- a/libavcodec/cbs_sei.c +++ b/libavcodec/cbs_sei.c @@ -262,14 +262,6 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, if (!desc) return AVERROR(EINVAL); - if (payload_buf) { - payload_ref = av_buffer_ref(payload_buf); - if (!payload_ref) - return AVERROR(ENOMEM); - } else { - payload_ref = NULL; - } - // Find an existing SEI unit or make a new one to add to. err = cbs_sei_get_unit(ctx, au, prefix, &unit); if (err < 0) @@ -285,6 +277,14 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, if (err < 0) return err; + if (payload_buf) { + payload_ref = av_buffer_ref(payload_buf); + if (!payload_ref) + return AVERROR(ENOMEM); + } else { + payload_ref = NULL; + } + message = &list->messages[list->nb_messages - 1]; message->payload_type = payload_type; From patchwork Wed Mar 10 01:06:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26292 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C553B448EE5 for ; Wed, 10 Mar 2021 03:06:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AD4C368A87F; Wed, 10 Mar 2021 03:06:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9DD3368A878 for ; Wed, 10 Mar 2021 03:06:38 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id p7so22296029eju.6 for ; Tue, 09 Mar 2021 17:06:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=N/vjF5Ng92MH1i5RPSjFPKKRq46YXVYkiNgAzCWQg78=; b=ahlh2snEPMTivfp6hjNdogRfDX/iR+RuuAACyHebQTN3PPFJpRE7hzfsM7exKPSWay TrIBDJ2oZ6tWPUaFDxKwcNLFHN7m0YmFijic1dVNgNsND3QreiaQEqFJ6hmd80NqgK41 BbwNX2UkjegOEi0HdPG4kq3Lyt7u52Y/G+moKuznq7ucwpAZdylyxGW/pykGYluFgdtv G7eRiDxuMbaEz5r8RwDgLSjahjJexVObHbY3nxPA212cfAri5hwUlMYQTMDB/YGPR+9t iEAxQgqtXfV/pfiD5BT4aCDiUXyS1TV76dsUg5mEzvpEWYFMvJOHY+SUwwVtIoIR81KM 2fIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=N/vjF5Ng92MH1i5RPSjFPKKRq46YXVYkiNgAzCWQg78=; b=YpPq/XHVRhLw8dAHyb8yiszCfZkjZDo6fNytbjYLUFMjBBjvQEmfuMmRTm4NV9n0zO l6Q32IQ7NO3wRBBzZXq1qbZCRS/oNw/w8IT1WgaqjtALXzi5ShIlKsTFSRSl17tUIxWr I406/gA2mct27yS0eVwQPwWeWDM1BwOf2+/kmepIChm29vjpYxyDsoLHIw6ScMAIbqy6 xYV1ncaxI7tDTcSGh6RpDlwEL0Ypo2fBh27IA+5o5YzwAeTMU3YOD8Q21d1U6HA3ruDa 9+RjqKGqh2CDLeI1I2cccsHEWMcXu4IDpQekHEtL6wppc+YyFnSv6eBnDD8Sd10zzza3 ol0g== X-Gm-Message-State: AOAM530K5l4fQcFI4Sb16Mx5i4/AM4aulvJKPgtygsJGrOnItVFu4n5y Ju2pdO/6a2rbrUAQdfippIZiD6rkuRk= X-Google-Smtp-Source: ABdhPJxKerAguiG7QTp5Vs51OQKN6baFZm5IQxyXe5xf8IPusQkBeZ/YeWeGRNmnuSubIaiKCIavqQ== X-Received: by 2002:a17:907:20c7:: with SMTP id qq7mr791367ejb.528.1615338397947; Tue, 09 Mar 2021 17:06:37 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id r13sm9960737edy.3.2021.03.09.17.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Mar 2021 17:06:37 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 02:06:01 +0100 Message-Id: <20210310010601.1142819-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 8/8] avfilter/vf_nnedi: Fix use of uninitialized value 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes Coverity issue #1473546. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_nnedi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/vf_nnedi.c b/libavfilter/vf_nnedi.c index 4229150668..b273c13944 100644 --- a/libavfilter/vf_nnedi.c +++ b/libavfilter/vf_nnedi.c @@ -903,7 +903,7 @@ static void subtract_mean_predictor(PredictorCoefficients *model) double softmax_means[256]; // Average of individual softmax filters. double elliott_means[256]; // Average of individual elliott filters. - double mean_filter[48 * 6]; // Pointwise average of all softmax filters. + double mean_filter[48 * 6] = { 0 }; // Pointwise average of all softmax filters. double mean_bias; // Quality 1. From patchwork Wed Mar 10 10:29:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26301 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DBC7E44A453 for ; Wed, 10 Mar 2021 12:29:19 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B56B568A6E7; Wed, 10 Mar 2021 12:29:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42DE068A537 for ; Wed, 10 Mar 2021 12:29:13 +0200 (EET) Received: by mail-ej1-f52.google.com with SMTP id p7so26240326eju.6 for ; Wed, 10 Mar 2021 02:29:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bJSJw1jt0mqwHbrLgeE3LvYRCszWToCa6yAfANzSqPI=; b=nOYPxfe2tLiLQgVVrj7o7wS/2X8NaD7OgKWJ8RBQMelygxFi1mGNmgDAHJQM9QOjtY HEdC6vskZtm4bi5FZtQEs1NK63bq3ASQM5ekIdaNqL/EP4BnOBWYDV7GbhYF9R+IebQU eaQAjr68keImlo6NAlhfFMvRmsY1XzBvUrXmeUdlMFjKsDxmrzbZje2pWsRNdTXixzg/ zCawFF1bArU72y0EU1gz0LbAlZp0YyNfkHdgJU9atRNQYqozsiATvPgVfYyXKVwIH/mt gOT2PY1iZg8q5d9ENruKYu3TErpbxDdxde1lPGuPUm+nJsb+VWrxNfZtOCZcv699gMY8 3luA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bJSJw1jt0mqwHbrLgeE3LvYRCszWToCa6yAfANzSqPI=; b=gdox3dgDUK51D6gJktYsLcXg0eH/FeH6ndEhqnmlrvQvkJ8184FFsvGX2Wxp6q908X xRO6IppDVFKI8tZ2ufQnCkhpmLMcEsdq418RnvssBKunc01ifWHVvDVaihMyG1vYMXos n1+SLWv9qq1Jdmvkrs33KCsl5Hjceuk7w+txf9X+asZB42leeamicC33+eafwGljD2eY wKPMJqvkHsKdn64oWhtqtpifXeB5wa1G2cxEEE/K3K66QgDXbL29mz1Q3ndDMqrdat9g J5q2/n8vu2GSkfi+w3v+bdKsK0gL3NNmg35Q37ShY605umwdcLpiJ6xG51nIOIzk7LK8 7CZw== X-Gm-Message-State: AOAM5325mc9umsIbrkM16YbXui8W2iqLAVDckY+T1N4EfZhdRIeBCAd+ KKtCyqEmnjVWvBNAluEj79XhZAxQus8= X-Google-Smtp-Source: ABdhPJw8UXZMOHsUgtp36cfJqu+s/V2//OhCokCpopm5DVKF/ULfagKPYj+YfCJez/6xm7t1NHzxZQ== X-Received: by 2002:a17:906:2bd7:: with SMTP id n23mr2896300ejg.502.1615372152509; Wed, 10 Mar 2021 02:29:12 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id u15sm10871592eds.6.2021.03.10.02.29.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 02:29:12 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 11:29:01 +0100 Message-Id: <20210310102901.1150707-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 9/9] avcodec/cbs_h26[45]: Remove redundant enum constants 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Unused since 8843607f495c95c1e67a3ce3d6f15dca6e252439. Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_h264.h | 10 ---------- libavcodec/cbs_h265.h | 9 --------- 2 files changed, 19 deletions(-) diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index 9eb97eae24..5a8641a333 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -28,16 +28,6 @@ #include "h264.h" -enum { - // This limit is arbitrary - it is sufficient for one message of each - // type plus some repeats, and will therefore easily cover all sane - // streams. However, it is possible to make technically-valid streams - // for which it will fail (for example, by including a large number of - // user-data-unregistered messages). - H264_MAX_SEI_PAYLOADS = 64, -}; - - typedef struct H264RawNALUnitHeader { uint8_t nal_ref_idc; uint8_t nal_unit_type; diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index 738cbeec2c..f7753f1206 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -26,15 +26,6 @@ #include "cbs_sei.h" #include "hevc.h" -enum { - // This limit is arbitrary - it is sufficient for one message of each - // type plus some repeats, and will therefore easily cover all sane - // streams. However, it is possible to make technically-valid streams - // for which it will fail (for example, by including a large number of - // user-data-unregistered messages). - H265_MAX_SEI_PAYLOADS = 64, -}; - typedef struct H265RawNALUnitHeader { uint8_t nal_unit_type; uint8_t nuh_layer_id; From patchwork Wed Mar 10 21:54:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26319 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2DB0A44B799 for ; Wed, 10 Mar 2021 23:55:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0E70868AAE6; Wed, 10 Mar 2021 23:55:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 00682688134 for ; Wed, 10 Mar 2021 23:55:01 +0200 (EET) Received: by mail-ej1-f45.google.com with SMTP id mm21so41773334ejb.12 for ; Wed, 10 Mar 2021 13:55:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=U8HVHpqe15t6GuJ+/hdo5yXfQax0BG54iv3UJymVhto=; b=ZJ4hHszTSBGRpQNxNHNkIczaXPSFXXF0wBFTCq1/ZfxLkVHSaGPx8o6iFfJwJRpD9z wlp7UfitvZhj7vO9mZz7ZHYX5fFw/DEDdXaJqi022sdlzXZojf+AN6BccjNO6YCLJ4Qd jDbaJSXqG9uZQCBdPk57xZ8ItuVd1DqjljYYkTsnUGknJCPrEAx6b5CySJX9waIostdu OdSt1Oz1o4yJX1rtqI6lthy7cd9Azjgh4dsTlVApnXQU5xaxtoUv/yH+72PtWfk4ounp Xyx1Hqiilx+zfKQB7CNsfEM9IUaDtLNFFjWfe4Gep0irjjqxi5SpNdIuRww4qP9R1ESc BFUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=U8HVHpqe15t6GuJ+/hdo5yXfQax0BG54iv3UJymVhto=; b=OAfb4x0GHpD0Bfe5WdHxiwcMEPk6Z9gnIKEtG1N+BnKzBr+Jvj0EMQg1DrP0ql7i9S FUpfhi5B0bNFzJhTrL/QibtnZBuxfr2Lx+9MT5dSvnbnyuofvmlUWLkk+VtC04VIDXL4 o/AvEo4jEK70I1TkkeR0hbRougJYaV1y10D1jlQxdWkyZW6ThvT5b0I5+YmDX67KyDXb xlDAfAlDQFYWDiHzMXAQ44YJVoYZAmXHu6Ll6wHXT/ZTRp//MvANOOw7ElhDbn2XgN/w fwOk0PtrTL9kKykUdXxL7zqawdYQxWI1bQXUYuHEVn4VI4IVQav0DNTCrie+Q/lV3+gU i+SA== X-Gm-Message-State: AOAM532aJ8Ty79xyEJz57w/oOPH+ueJHfo3nhCcbwY0lGZ8Ut1kEmJ/o 0tE/JSx2bw91ubd13/6ewx3um0viWV4= X-Google-Smtp-Source: ABdhPJzfQD2Ch8mA8p5FrZjoc5ilMAtSzbMgNUGUgBtEbopS/+zaqf1Wd/7ghQ+LuF9jaeatOeLKxg== X-Received: by 2002:a17:906:da0e:: with SMTP id fi14mr36772ejb.188.1615413301259; Wed, 10 Mar 2021 13:55:01 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:00 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:33 +0100 Message-Id: <20210310215446.1396386-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/23] dnn/dnn_backend_native: Avoid allocation for checking file magic 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c index 3bc253c1ad..5336cd765a 100644 --- a/libavfilter/dnn/dnn_backend_native.c +++ b/libavfilter/dnn/dnn_backend_native.c @@ -114,10 +114,9 @@ static DNNReturnType get_output_native(void *model, const char *input_name, int // For DEPTH_TO_SPACE layer: block_size DNNModel *ff_dnn_load_model_native(const char *model_filename, DNNFunctionType func_type, const char *options, AVFilterContext *filter_ctx) { +#define DNN_NATIVE_MAGIC "FFMPEGDNNNATIVE" DNNModel *model = NULL; - char header_expected[] = "FFMPEGDNNNATIVE"; - char *buf; - size_t size; + char buf[sizeof(DNN_NATIVE_MAGIC) - 1]; int version, header_size, major_version_expected = 1; NativeModel *native_model = NULL; AVIOContext *model_file_context; @@ -138,20 +137,10 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, DNNFunctionType f /** * check file header with string and version */ - size = sizeof(header_expected); - buf = av_malloc(size); - if (!buf) { + if (avio_read(model_file_context, buf, sizeof(buf)) != sizeof(buf) || + memcmp(buf, DNN_NATIVE_MAGIC, sizeof(buf))) goto fail; - } - - // size - 1 to skip the ending '\0' which is not saved in file - avio_get_str(model_file_context, size - 1, buf, size); - dnn_size = size - 1; - if (strncmp(buf, header_expected, size) != 0) { - av_freep(&buf); - goto fail; - } - av_freep(&buf); + dnn_size = sizeof(buf); version = (int32_t)avio_rl32(model_file_context); dnn_size += 4; From patchwork Wed Mar 10 21:54:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26320 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 417BC44B799 for ; Wed, 10 Mar 2021 23:55:42 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1542268AB2C; Wed, 10 Mar 2021 23:55:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A63468AAEB for ; Wed, 10 Mar 2021 23:55:35 +0200 (EET) Received: by mail-ed1-f52.google.com with SMTP id dm26so4473edb.12 for ; Wed, 10 Mar 2021 13:55:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=GTnyDLxg3nBelwGY9R+6xNjxri5Ql0TxpH1NDxYY/W8=; b=JBJcnbfPMee9GskwzZKTAEwZpvBmdfnnqdYRgm+Xq9zWc2QTBb257Z2rx/CCvW3qnd Ki9lYgNbIEBferjEfm9knMM9ZufmZKeuSl3LBX2C/ANX1ueCW21MfeLcTDRV9ltT2J8G cHxPaL81XbfvQT8tSmA6iG1UOTuGdXcHlz0Y5KPKv96yqY0ItSUdavFFGxTjdo1f8qeM xu1J8gYz3h1LgOrhHGLkIeuSGDJsoH0kx7wI0ffEjMOJz8/rkZzsZ7O57DXG5U6WmRJe ekbDYszp3qdqj8KCnEk81CX2aNIN818cjjZm0gE8GyGvHDfahjiocigcJp/QQserp5Qf XoVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=GTnyDLxg3nBelwGY9R+6xNjxri5Ql0TxpH1NDxYY/W8=; b=rgZ2uRNnCTtH0OAllTBkgvYDGTHe5vU+gfoLIzWBJ8aIYDbq5r2pvlVEBwRV3J3V6E 0tRdfYihy3S5dLiWvuPo4peMH2LmMfPQ0xnTpWoZD/tEBpuAmXsI3WosZQ9L5WvDhV4T nHR1n+3UtQjPt2Yq9X5PEkVgWOlGmjwprELyrBIGtvt5G3omDXddnSz9oF6N/5U8h2zL HEtZqwOye8E+K1y5ZWeEEIoceJkUkF0FOLrz1XzhlS3KHKse5FoX8vy8DZ+Hm5gZ0yHI S05Zo2UWBhCJak96kX1Ffc5msEvd5H+OwsYMRk3iTOxU2LxHj9kj1IjGxdLVgYiQem9C zXxg== X-Gm-Message-State: AOAM530KNNKO/Sj2aufg18Ee/aXlcnYlVvvgAEnjh6WiD8+E3hoIgh9H 5h+iF7mwwy32Xh5YJQx3mP/DkAZS7Lo= X-Google-Smtp-Source: ABdhPJyN0L7Bm2x2NTLt6K8dNHIGhOr/u3tfnv9xDfpUEBm4Xct1tb2QFPN8RMCb70NaPKWIMzuEJg== X-Received: by 2002:a05:6402:1d95:: with SMTP id dk21mr5475348edb.280.1615413334947; Wed, 10 Mar 2021 13:55:34 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:34 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:34 +0100 Message-Id: <20210310215446.1396386-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/23] dnn/dnn_backend_native: Fix leak in case parsing options fails 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c index 5336cd765a..fd1f9e299d 100644 --- a/libavfilter/dnn/dnn_backend_native.c +++ b/libavfilter/dnn/dnn_backend_native.c @@ -157,12 +157,12 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, DNNFunctionType f if (!native_model){ goto fail; } + model->model = native_model; native_model->ctx.class = &dnn_native_class; model->options = options; if (av_opt_set_from_string(&native_model->ctx, model->options, NULL, "=", "&") < 0) goto fail; - model->model = (void *)native_model; native_model->model = model; #if !HAVE_PTHREAD_CANCEL From patchwork Wed Mar 10 21:54:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26321 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7CEDE44B799 for ; Wed, 10 Mar 2021 23:55:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6BE0268AB37; Wed, 10 Mar 2021 23:55:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3064B68AAEB for ; Wed, 10 Mar 2021 23:55:36 +0200 (EET) Received: by mail-ed1-f54.google.com with SMTP id dm26so4494edb.12 for ; Wed, 10 Mar 2021 13:55:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=HbgVwmhEZOXC/fe3OjSEyt3/h2QEUlCZ2raJnIAgfhg=; b=nun08Av97mUbJMnGZHNJbC9axB9oIEA8s2u57cReSSJN5yKjxyKr5XTCNroRQKD40O jwAXbQ0tSMwwW4DwJ8/HkiIJbFFSU7a+mz52ut9NYVPl2XpI+3RUt+l7Oiuv5/E1IxAS TcxhzVi7EUVc+mJ00IudRCkgnmpOg/Nv63wN+uZ80u44u5g3TFspHFru8PUTF4mFMMh/ uIwhfONUJaeCv++OVNwWkHMRL6zr6zCKS4LDl8OsVMOYtJ1qIml7RNbDaa1HCHrL9LIA He7e3fU35e58xVQ4kSe8HBYqVQ8Hfz4vJasLDYhrtiupZMUNwZmtM8fy3hI0AbEGAIpF qeUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=HbgVwmhEZOXC/fe3OjSEyt3/h2QEUlCZ2raJnIAgfhg=; b=n2JkWQPHeqs2TG5y9en/690F4QN5ZNQBNufzqwcvX2JjyeAbIAaMC7vWDCEjiF+hQ0 +7JLUJmeVHSp3oH/HIyyzzwNAjJU590BQdOH9toWB1f4VdiRihRqcrnRVbUFehClwcIX jOjfOQtJRVVygodZA6rjKO56L++lHQdmgKBSafiuPiKwit1xmI6Ho09OLVw05doSIhBF 8UteN6raQ7sJzevOnMNbyuOqpP7JKStOtw+iwCzhEpGlOcIpvm/nka7yne4s15Pgx6bA B8MY0AbSdzmHPJXwuRh40JxFp6ixets3G50bp9S/KQ+qhIaHh3uIfT8kz6i6iWE1jVms QeQg== X-Gm-Message-State: AOAM530uO6E8j7zOQ7eh7JWCrZIqKWKKZzjtOt0G1ovOQUvmhMqbVZK5 A77fzsiRXN72ewT7/iFCCSGg7QKALDE= X-Google-Smtp-Source: ABdhPJzbjxbRdtcNgpv7lr0g3SaJfMh+qEIHThS4EdqPF0b6yjRizUA/BImS2TpezR0zsnk66i/J3g== X-Received: by 2002:a50:e702:: with SMTP id a2mr5573210edn.3.1615413335637; Wed, 10 Mar 2021 13:55:35 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:35 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:35 +0100 Message-Id: <20210310215446.1396386-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/23] dnn/dnn_backend_native: Don't use asserts for checks 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" asserts should not be used instead of ordinary input checks. Yet the native DNN backend did it: get_input_native() asserted that the first dimension was one, despite this value coming directly from the input file without having been sanitized. Signed-off-by: Andreas Rheinhardt --- get_input_native() only asserts this for input operands; so it might be that the check below should also check for this (depending upon whether 1 is a valid value for output operands). libavfilter/dnn/dnn_backend_native.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c index fd1f9e299d..b3c41af94e 100644 --- a/libavfilter/dnn/dnn_backend_native.c +++ b/libavfilter/dnn/dnn_backend_native.c @@ -231,6 +231,8 @@ DNNModel *ff_dnn_load_model_native(const char *model_filename, DNNFunctionType f oprd->dims[dim] = (int32_t)avio_rl32(model_file_context); dnn_size += 4; } + if (oprd->dims[0] != 1) + goto fail; oprd->isNHWC = 1; } From patchwork Wed Mar 10 21:54:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26322 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5C79744B799 for ; Wed, 10 Mar 2021 23:55:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4B06668AB79; Wed, 10 Mar 2021 23:55:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E40A568AB05 for ; Wed, 10 Mar 2021 23:55:36 +0200 (EET) Received: by mail-ej1-f43.google.com with SMTP id e19so41902499ejt.3 for ; Wed, 10 Mar 2021 13:55:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=VtTao4rJFhnLxnaLHRe5V5Dl11ie/ScEheVTSNbVy14=; b=gfgEqC4oF/mvU4qanINsJSOCMRk0QIX/bag0ffKyMCX7BzziHIeXsbEJSi5AEAfuBg FlWw56wTAnIPB+PrnX6MHDwB1ee2dHXa6fm/ImMsVFUEDQh3KsRGivPFvqKQKLiDjmSh tzNozI/5OAnj4GRkvzaZV47qOVyAYIEdi6ZxRDSFJ5a/tw8rrq6VjfwUpVthNwHVTteF 5rsnc9HrFsSbGbcpeHiA/0vNHInGiQuSpfiKh1ao+jASHVjry5g2RxzcuHQMebkmhXZN OXlCAvhuW/wJX32WgcfXU5ixn3RTubkLW/jYvqnt7t+i83tx90PwBrG7WOcbjk8/rAht /Tjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=VtTao4rJFhnLxnaLHRe5V5Dl11ie/ScEheVTSNbVy14=; b=R5voeQDh8Jkvn5iZi4Hjk3T6HV6JB2BxPJe0jYqGkcMniwM9tOMl5jcBxY7FpbpzsY Rzx8YzrYOb/rk7BBb0sQTUCBcRhdn6sBcNugIsgqOz37OzQDFxsCBu1LHij3inkm/0iH HR9HLidxI5cErukXL58rRY8AEIO2lZdBfGXydDn8apRisb8Bs+1KKBPJds80P02nTRre IgMW7CnjxSqIrIgMDSEb79fizJtKTa9rHNF1MBHhlAjkuxZbM6zDApBU0B3JmfO6llus q7zfhK2BmS7ZtPmunksGZ22eZVJ2GfbQSLH9KWtPAXd94X0iktYv4nRNvCCrtGbzAe0q w8wg== X-Gm-Message-State: AOAM530OiV9EFs/FeIcnfhw6sJjgzqwBBZc3ybtk0pesYnbWw0KX8Zdy V9LBoqW1PdQHiAiZA/gNcGQXfgqcc78= X-Google-Smtp-Source: ABdhPJzGzzWl/Uh30EE4kqGE9k2uk5HhT18xconE0Bx0VLzvkhU7cMXf64KDn2cdUd92Sx4TXPUN4g== X-Received: by 2002:a17:906:311a:: with SMTP id 26mr817ejx.395.1615413336283; Wed, 10 Mar 2021 13:55:36 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:36 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:36 +0100 Message-Id: <20210310215446.1396386-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/23] dnn/dnn_backend_native: Fix typo in log message 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/dnn/dnn_backend_native.c b/libavfilter/dnn/dnn_backend_native.c index b3c41af94e..0f26febb5d 100644 --- a/libavfilter/dnn/dnn_backend_native.c +++ b/libavfilter/dnn/dnn_backend_native.c @@ -330,7 +330,7 @@ static DNNReturnType execute_model_native(const DNNModel *model, const char *inp native_model->layers[layer].output_operand_index, native_model->layers[layer].params, &native_model->ctx) == DNN_ERROR) { - av_log(ctx, AV_LOG_ERROR, "Failed to execuet model\n"); + av_log(ctx, AV_LOG_ERROR, "Failed to execute model\n"); return DNN_ERROR; } } From patchwork Wed Mar 10 21:54:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26323 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3FCFF44B799 for ; Wed, 10 Mar 2021 23:55:47 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1CD2E68AB3B; Wed, 10 Mar 2021 23:55:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8DB8168AB33 for ; Wed, 10 Mar 2021 23:55:37 +0200 (EET) Received: by mail-ed1-f44.google.com with SMTP id l12so71738edt.3 for ; Wed, 10 Mar 2021 13:55:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=FyOFa6JWM36A+DsNA3lvlpyNwyYcw0lkEHYUirPmiUA=; b=YDbN3MdiZt7lL/YR1RxspOl6hD70gBToORJ9nwuYJWjbirRsPbRVyIzUHPhtO3Vq8n 4THmR8l/bPBooMw+5m7aTdUf9GBCAleTnZR5fcPG8256voHGSB1XOco9xDZExFtKeD1u ZgPLLZ3bvwCyXrn2J3Hpdmc7N8EpH1/uoCbh3FZdlyikGmXiqOxdvqmMwUHVRxfaiYp4 Yn4L6rjH/LkX6TiJIN6T/7MemAVU4gV1t/mZ6lhh5GW96030VKvjuDaYlwkozjIAKRsk pCVcCQAUBCpsNAIWxnlrSP9lgAeX1vubMYj/b9kUiPUQVIMHBtw2E/Bo2wPsSQa+sKN0 co5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=FyOFa6JWM36A+DsNA3lvlpyNwyYcw0lkEHYUirPmiUA=; b=j8lS2dKVT28Vc6EOlr0N40r5GqYFfqx80LZPrNJJtb5sMJttJs3otZYtPg00vjAhhr +5hWIaJi/GAkQWTFI61bwxKijFnZCN+fOopas50yH+VnplJ9gQDyx7R7WHXp1Fu4Z4Zw 8w1F7HpJfLQRv8cDh2Q3Do9e33Skw7DWch8bVlrOY/BFCVB6F7hSZIfUA4t535TzOD/3 vqB/Q2MqZ5gCStkzmmzIUV6fcqkHEjM7W42h7rjHRWzpqjsccnZuUWlJ5WAtV1uY4mvG w+G2r0V8llg4DtQAh00oz1LKQaBd0K+IKFnf6B9ElONEa8zQo6kMaGkJiaojIKbbfABi /QXg== X-Gm-Message-State: AOAM530mA+Yu3XRdzrPtyDokDlhFLmLWWl3vcnZ5VFMcyrCGEsbkjsAG jC6Ky97aVPIUS4IEC/Ue31btcqIyAew= X-Google-Smtp-Source: ABdhPJw9fMFFbJ2ZV3wnb37eAltYwrKbos7OOEELGhw+sdx+GC1THS2A37Psu3diQVj/HiDwzC4WYg== X-Received: by 2002:a05:6402:6cb:: with SMTP id n11mr5632651edy.198.1615413336876; Wed, 10 Mar 2021 13:55:36 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:36 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:37 +0100 Message-Id: <20210310215446.1396386-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/23] dnn/dnn_backend_native_layer_conv2d: Fix memleak on realloc failure 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index b5c2c394ef..2b83896da9 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -197,6 +197,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera int width = operands[input_operand_indexes[0]].dims[2]; int pad_size = (conv_params->padding_method == VALID) ? (conv_params->kernel_size - 1) / 2 * conv_params->dilation : 0; DnnOperand *output_operand = &operands[output_operand_index]; + void *tmp; output_operand->dims[0] = operands[input_operand_indexes[0]].dims[0]; output_operand->dims[1] = height - pad_size * 2; @@ -208,11 +209,12 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n"); return DNN_ERROR; } - output_operand->data = av_realloc(output_operand->data, output_operand->length); - if (!output_operand->data) { + tmp = av_realloc(output_operand->data, output_operand->length); + if (!tmp) { av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n"); return DNN_ERROR; } + output_operand->data = tmp; thread_common_param.output_data = output_operand->data; thread_common_param.operands = operands; thread_common_param.input_operand_indexes = input_operand_indexes; From patchwork Wed Mar 10 21:54:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26325 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4CFFE44B799 for ; Wed, 10 Mar 2021 23:55:49 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2C82D68AB7C; Wed, 10 Mar 2021 23:55:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DB1368AB43 for ; Wed, 10 Mar 2021 23:55:38 +0200 (EET) Received: by mail-ed1-f54.google.com with SMTP id bd6so18093edb.10 for ; Wed, 10 Mar 2021 13:55:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=levCGK4T3hRAQ3ILXIE03lTx33MCny2/um3IVBwcWQk=; b=VwYPwkKtTgqaa6rpGInLNcu9q+eLjdW05LPmhm/EOauq+jtJUD8yaI8XgVEOlqknX5 dRYqTLCBx9vmKpGEh1XQoPc/YQ4QCQiyMBAo0WbKa2P+G/ZHSsWTw95GLWMfgejsz6UT 9mqwyFPXEcW08v23C5TsABjb+K8mOPJTfSLMkBb1kXhJXlSMKa45VuSkR0eKKL4ilDRl fGC+9pOmi+kgxhIgM+9wp0XlwAHMgrxyWlfznP+jAta7i8trkOSPVKaPhuuoJfCoCFOF iO8QHNACtY+6jzLOoOfs+puRS8RyMd6V9xdp+cGqzdxF451J/yK3/4Ja7r45vmgROKZZ hSXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=levCGK4T3hRAQ3ILXIE03lTx33MCny2/um3IVBwcWQk=; b=kEao+MG52HrPQbFbAnbZrRF7LLeGc2qiU2TJwPZUHgVFyfqKE3WRqvPWY1Vbkxqjr1 j/aVnZsW9qHb6ShQ/r8j+bDgvwwAurnDOVE8jMQSCvhsDXQIocxwYXj69LpdCAhtPL6U 4i6Xrwo0TcCsTLfPjROb/I8hHRk93zdlHT8QT8CHoUCqqdKT0xK8LITxI1pewUM+aAdf w67sSGhKaTJfylSYc1hWFVbNOdBMdMAOMvZqyXyGoxnYoblUB4AIwwND2HxLWgMpzkWS oeBnOtrN1V3BBf5UWp9ZDrSjxsOV972uV/OPD9dWCyMIWzNyFC4DcJ3jhrwZW8oDcLZF HRuA== X-Gm-Message-State: AOAM533TSnGFG8UZw+OpLPDlIdTpzZHJOtauKD7YD7kB79bwiwjVzv7J 2/kVsdzeE5BomJyO45QlFwEeeNU280s= X-Google-Smtp-Source: ABdhPJywt6VgFOb+wlLpoCWtfgxmt2BOjBW0H2Tgek5j/LW66i/3TXA/ZXgjSWDqYyjnNV5YmvkASg== X-Received: by 2002:a05:6402:35c9:: with SMTP id z9mr5508841edc.94.1615413337573; Wed, 10 Mar 2021 13:55:37 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:37 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:38 +0100 Message-Id: <20210310215446.1396386-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/23] dnn/dnn_backend_native_layer_conv2d: Join two arrays, avoid allocation 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes Coverity issue #1473507. Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index 2b83896da9..2e5aacdc2b 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -38,6 +38,9 @@ typedef struct ThreadCommonParam{ typedef struct ThreadParam{ ThreadCommonParam *thread_common_param; int thread_start, thread_end; +#if HAVE_PTHREAD_CANCEL + pthread_t thread; +#endif } ThreadParam; int ff_dnn_load_layer_conv2d(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num) @@ -187,7 +190,6 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera int thread_num = (ctx->options.conv2d_threads <= 0 || ctx->options.conv2d_threads > av_cpu_count()) ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads); #if HAVE_PTHREAD_CANCEL - pthread_t *thread_id = av_malloc_array(thread_num, sizeof(*thread_id)); int thread_stride; #endif ThreadParam **thread_param = av_malloc_array(thread_num, sizeof(*thread_param)); @@ -230,17 +232,15 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera thread_param[i]->thread_common_param = &thread_common_param; thread_param[i]->thread_start = thread_stride * i + pad_size; thread_param[i]->thread_end = (i == thread_num - 1) ? (height - pad_size) : (thread_param[i]->thread_start + thread_stride); - pthread_create(&thread_id[i], NULL, dnn_execute_layer_conv2d_thread, (void *)thread_param[i]); + pthread_create(&thread_param[i]->thread, NULL, dnn_execute_layer_conv2d_thread, (void *)thread_param[i]); } //join threads, res gets function return for (int i = 0; i < thread_num; i++){ - pthread_join(thread_id[i], NULL); + pthread_join(thread_param[i]->thread, NULL); } //release memory - av_freep(&thread_id); - for (int i = 0; i < thread_num; i++){ av_freep(&thread_param[i]); } From patchwork Wed Mar 10 21:54:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26327 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id F0E5B44B799 for ; Wed, 10 Mar 2021 23:55:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DA92968AB40; Wed, 10 Mar 2021 23:55:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E12F368AB03 for ; Wed, 10 Mar 2021 23:55:38 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id ox4so26222842ejb.11 for ; Wed, 10 Mar 2021 13:55:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=qPKvmu1GHnSR81mXwxSxkTLaH3qQI3fyaI54jJoBy9I=; b=Lm1XI6n/Tz7m2Xbvby2gFyPLSq9sEJmrq9yKO4dCeQysLHfXtqtl0u9DTL8kGId0kg dyT1f8BMNYcrSjGrtUjHZDkpNKZu723HLD20Apo23mhsqD2CSg0RLOd1NXtgIdwZgIXH uHIG4pA7AZO5EnS14PuXMqTyLYs9oMoQycWu3ULXGBCigsuijGyXtPTT154ZvYKYyEi/ es90fctF+JHXYoXvWmAqtRYgNf6gBVRwOAZE/PnHPyaE8ta+L3T8pCyyVVX3KyUX9zGA kV8SktOfG7t2BjCMMyUSY1RC0wSLZn91Lp65rMPPjaeD1vbwz5YtWr0gu43nJuIj0/jo jP8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=qPKvmu1GHnSR81mXwxSxkTLaH3qQI3fyaI54jJoBy9I=; b=odQzjftn8uBFNrw6kY2qEEWQikBDZ+LqElmiRFvwPiFBCPDhMVxcK13RdgrlSbd7XP QpOgw2URduA5L9ahbse00AuDCrjahJnb6/AacyNKqf0KggqkI+Mx1oQCOGuOSFWaMvoM UXbTO1LUfuwHf29arHkttUVXjysiSMDTGdSivZNDGxFVy6cBDnR2XaYrfuYN+jqORbrA QO/zYPOYWINGvoAQYPt5nkqvjwT9x81Oq+HEyTOoUK08sE42eO/zVYq/OIs2X+GLUgHo robEZ/nsYEe6FthdAH+WHQyiIrisAe47XrInogakVEzYlU8T7/IlezUouhQVsJV9AKKk XygA== X-Gm-Message-State: AOAM530EyNb5AlDbXybuRuHNaZe2Vvym2RU6+RulyPgCSRGcHhI/4QZZ 8MxtTCUeDJD0k0HA3IRzXOUenSkAFDw= X-Google-Smtp-Source: ABdhPJxMfZPDC5W22/JGBSeB4ULERwUAYRn6b641IXQ/QyfDa4rlPbJBb2yikruEN3NxSL7XR3viTg== X-Received: by 2002:a17:907:7745:: with SMTP id kx5mr18615ejc.3.1615413338259; Wed, 10 Mar 2021 13:55:38 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:37 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:39 +0100 Message-Id: <20210310215446.1396386-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/23] dnn/dnn_backend_native_layer_conv2d: Avoid allocation when single-threaded 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also fixes a memleak in single-threaded mode when an error happens in preparing the output data buffer; and also removes an unchecked allocation. Signed-off-by: Andreas Rheinhardt --- .../dnn/dnn_backend_native_layer_conv2d.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index 2e5aacdc2b..cdf65974b6 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -187,12 +187,14 @@ static void * dnn_execute_layer_conv2d_thread(void *threadarg) int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, const void *parameters, NativeContext *ctx) { +#if HAVE_PTHREAD_CANCEL int thread_num = (ctx->options.conv2d_threads <= 0 || ctx->options.conv2d_threads > av_cpu_count()) ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads); -#if HAVE_PTHREAD_CANCEL int thread_stride; -#endif ThreadParam **thread_param = av_malloc_array(thread_num, sizeof(*thread_param)); +#else + ThreadParam thread_param = { 0 }; +#endif ThreadCommonParam thread_common_param; const ConvolutionalParams *conv_params = parameters; int height = operands[input_operand_indexes[0]].dims[1]; @@ -244,15 +246,13 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera for (int i = 0; i < thread_num; i++){ av_freep(&thread_param[i]); } + av_free(thread_param); #else - thread_param[0] = av_malloc(sizeof(*thread_param[0])); - thread_param[0]->thread_common_param = &thread_common_param; - thread_param[0]->thread_start = pad_size; - thread_param[0]->thread_end = height - pad_size; - dnn_execute_layer_conv2d_thread((void *)thread_param[0]); - av_freep(&thread_param[0]); + thread_param.thread_common_param = &thread_common_param; + thread_param.thread_start = pad_size; + thread_param.thread_end = height - pad_size; + dnn_execute_layer_conv2d_thread(&thread_param); #endif - av_freep(&thread_param); return DNN_SUCCESS; } From patchwork Wed Mar 10 21:54:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26328 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DACC444B799 for ; Wed, 10 Mar 2021 23:55:51 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C1A5C68ABB7; Wed, 10 Mar 2021 23:55:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 985FA68AB25 for ; Wed, 10 Mar 2021 23:55:39 +0200 (EET) Received: by mail-ej1-f43.google.com with SMTP id lr13so41886414ejb.8 for ; Wed, 10 Mar 2021 13:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=buO2r/hEIed8PYuB7UVi5fPGeQIKUFoHhTjs/y+L/mM=; b=OK2K+bkYdPpobPV96xT+fIJYaogpCnE5OGFxEKAIc6XygRKPaItw2dfgzuwcN5kbMt RULqrz7KRlxsId6A8iOC+1licRoOc+eFrQLneQcV2UhqwO083G1DKut5jK28FMlAXy3k siv8VHrSQbZlmiwt2HL3mWNCitl3hCCKUydUs7r4YST+8Mz2p159e3zkCjS6j+uBeUJh FD7mC6omsg/sv6jhUSS1iBGtPXDrD6jTCbaggKvw5C3JcT1ADJ4BjLass3Cq9gu9wfid l1PsiWMdCyeoXdGmApLleWnfh/bb3UICaXrLo4Wy7z9VBGw5zQEV1GClDrDij44Yc7TD /JeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=buO2r/hEIed8PYuB7UVi5fPGeQIKUFoHhTjs/y+L/mM=; b=CGWCrzvaFjmFwqmkxI41Aze5bXiU5/CjwCU0n1DFOHr8SysxGHi6hPNFa8DfFfUpGq QW3nS+YJhW/XzQL2eScRtq59N1qw7I8OqGn6Z/+kVyVUFrE2uxsJogB1Kc0w7jdR+OiT NtAEJMe+gmCaxWksnMiBmbFaKXcOhcrMRnR21R4ByypVdV88P6WZkdX5sT9u2KH8g3xn BOWUMQNP7vcmz/ciPaSZRNEYLfwdzunwrImpn8if+KOGR/yRyMOh3YbFOZOLE2yNszUc Y2ymB/G2FnY5yMfRIUmokqo911QhiWF+jKF7GNblx5fjqGLuhcuxjS38IwylbuaaDM8E QPBg== X-Gm-Message-State: AOAM5322WXjpfa77fr+3YdIDgQ6Lzgr5dZkmB3XmIaI+pPdEWC6bzmuz ua+zoZPyC+YY4KHUrt8HrTLzav+7eGE= X-Google-Smtp-Source: ABdhPJxnFNXpA5Y0/f4f4E6g14UAUBli2x8MoeJKNmOm895vr9bivQr4CFZsGTHvbr+t2rZKLk4Fcw== X-Received: by 2002:a17:906:af91:: with SMTP id mj17mr32448ejb.230.1615413338859; Wed, 10 Mar 2021 13:55:38 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:38 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:40 +0100 Message-Id: <20210310215446.1396386-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/23] dnn/dnn_backend_native_layer_conv2d: Fix memleak on error 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If an error happens when preparing the output data buffer, an already allocated array would leak. Fix this by postponing its allocation. Also zero-allocate the allocated array for safety. Fixes Coverity issue #1473531. Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index cdf65974b6..c2073a02de 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -191,7 +191,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera int thread_num = (ctx->options.conv2d_threads <= 0 || ctx->options.conv2d_threads > av_cpu_count()) ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads); int thread_stride; - ThreadParam **thread_param = av_malloc_array(thread_num, sizeof(*thread_param)); + ThreadParam **thread_param; #else ThreadParam thread_param = { 0 }; #endif @@ -227,6 +227,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera thread_common_param.ctx = ctx; #if HAVE_PTHREAD_CANCEL + thread_param = av_calloc(thread_num, sizeof(*thread_param)); thread_stride = (height - pad_size * 2) / thread_num; //create threads for (int i = 0; i < thread_num; i++){ From patchwork Wed Mar 10 21:54:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26329 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AD65944B799 for ; Wed, 10 Mar 2021 23:55:52 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9769568ABCF; Wed, 10 Mar 2021 23:55:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3EC0468AB37 for ; Wed, 10 Mar 2021 23:55:40 +0200 (EET) Received: by mail-ej1-f52.google.com with SMTP id hs11so41876929ejc.1 for ; Wed, 10 Mar 2021 13:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=ZdrK4DNkm8vbylkHO80I0C0b7DPWucvX4sqyOItCZkQ=; b=fChHSMHnIGmNLZTAfowBKOtu0XWf8dYbgwlNFNTNSzDhTZgAfYHiVkET+qyjCzPMjZ +7hhT7UQvLpEyjT8x3CmH+PnTDMGA+ya7vtsED93+HOhbbxwecM+Nhuc3nUrViv1B4mY RhzDXmmN48BMLLPU0yZoZNQ6kaKZbZEP08kWlaIpixYquRIeNRo7CD8f6CnlDtArZnve TIvzW5a55BW3gPz7Yrf56Ye8JqZJS9zNUGKObX3p3wsKeS5lyRz+FAqrxiTkQzSQvZkj 2wTkLQUrY6p8ssxqcr4949TWUqOeEQm2av7j1UZGKsvLBXMXQR8Sjr9Fftkvzyi0zZ/4 1FSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=ZdrK4DNkm8vbylkHO80I0C0b7DPWucvX4sqyOItCZkQ=; b=LzoGKZL+ZIzchYKUrohTOHvcupI8JPlIDAn3nb7cr4lrBc/VVNXZLoquA9M2e666yu 9fg++0Hj2EyJhWPqz8OS+kW+6Bsukjh/ezOa80ecYZjwdb0/NBiNsLwPjmCOUix6edsL S/k08BjNNBV2WsxjtkNwXrbEcs8oaSt7P4lTO7qtawqws4v7oD/kUDXqahL86SnvNfPe yQ4rNBagDyVSzLT3fXw3Rtjh36x2JM7G/EtYjllY/JC11PuP5DLYUFTaCP5nKGaJ+PrP W/4jtLgaf4es+J4gBRpCRQ/8/sOWapVowQQejwiCj8fsE6sEJsOIRQoHnExy3CaPMUDJ jFzw== X-Gm-Message-State: AOAM533pxYwa5IA/KBCsKkFeLsDtQ6rjtborwaHAEREfay0c6WAjFoQQ fZORYBNmsHkdEDOBKZ3awCLutF7yVBc= X-Google-Smtp-Source: ABdhPJzZOUAeHQCaxVpNrZwtgKtNHofVB4RD96OhLNFlgm8Ico0NgDTzTX5yynNMufpjNfBpdbqplw== X-Received: by 2002:a17:906:358c:: with SMTP id o12mr39068ejb.156.1615413339524; Wed, 10 Mar 2021 13:55:39 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:39 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:41 +0100 Message-Id: <20210310215446.1396386-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/23] dnn/dnn_backend_native_layer_conv2d: Avoid separate, unchecked allocations 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- .../dnn/dnn_backend_native_layer_conv2d.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index c2073a02de..94a07c1fdb 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -191,7 +191,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera int thread_num = (ctx->options.conv2d_threads <= 0 || ctx->options.conv2d_threads > av_cpu_count()) ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads); int thread_stride; - ThreadParam **thread_param; + ThreadParam *thread_param; #else ThreadParam thread_param = { 0 }; #endif @@ -231,22 +231,18 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera thread_stride = (height - pad_size * 2) / thread_num; //create threads for (int i = 0; i < thread_num; i++){ - thread_param[i] = av_malloc(sizeof(*thread_param[0])); - thread_param[i]->thread_common_param = &thread_common_param; - thread_param[i]->thread_start = thread_stride * i + pad_size; - thread_param[i]->thread_end = (i == thread_num - 1) ? (height - pad_size) : (thread_param[i]->thread_start + thread_stride); - pthread_create(&thread_param[i]->thread, NULL, dnn_execute_layer_conv2d_thread, (void *)thread_param[i]); + thread_param[i].thread_common_param = &thread_common_param; + thread_param[i].thread_start = thread_stride * i + pad_size; + thread_param[i].thread_end = (i == thread_num - 1) ? (height - pad_size) : (thread_param[i].thread_start + thread_stride); + pthread_create(&thread_param[i].thread, NULL, dnn_execute_layer_conv2d_thread, &thread_param[i]); } //join threads, res gets function return for (int i = 0; i < thread_num; i++){ - pthread_join(thread_param[i]->thread, NULL); + pthread_join(thread_param[i].thread, NULL); } //release memory - for (int i = 0; i < thread_num; i++){ - av_freep(&thread_param[i]); - } av_free(thread_param); #else thread_param.thread_common_param = &thread_common_param; From patchwork Wed Mar 10 21:54:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26330 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A862844B799 for ; Wed, 10 Mar 2021 23:55:53 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9120368AB82; Wed, 10 Mar 2021 23:55:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D3A9268AB79 for ; Wed, 10 Mar 2021 23:55:40 +0200 (EET) Received: by mail-ej1-f44.google.com with SMTP id e19so41902725ejt.3 for ; Wed, 10 Mar 2021 13:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=kfLZKRyZJ/Qr3S24SiLMtbjIHn0pu5sbNVDntZrgVGs=; b=iDErhvv+iNTcO28dLHeO9zxShR3yiDnPf6H0cT/0q9uG7YCDE3Qyz17cpiHYYOJuuu G8Gt8pAEVG0ZCWNjHUP3GS+tdoiMh9/BQQNoYIdM9kBCTk9tffucC3eYC+Yak83ZLQ75 I3QDjH/l1GoVRQznpNpbMR6G8rYiqcL3VgYdZDPYckk0wrivR9yTwfsw1Jz5jiesuUuU 6/f8TtscqEUPNOlDxeIdF+7hlYSCGmBClsfNufbEX00/QFsa/0Vpc/vObazdqgqPVvX1 ZZX0qX7Q0BJ6O+jVJuvwiS3afMsGzN9u99TLHDRnwdbCGJMeC55spRH+VOE4S3Pl80Nt RQNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=kfLZKRyZJ/Qr3S24SiLMtbjIHn0pu5sbNVDntZrgVGs=; b=YIK4vnwqc5Ca71IC1Wixp/2aqWrwYCtaIkd+Mqcr6dNAY+nETjFvtfuXtieBwLNDzz KRBsosAMKFC8423kdu1XQBq4X6175Dz2lc2iFZZRnkw1cj7QiWcefCNJKrrDgx8sD896 R7xCBydZ8rNXLmBQzEnuRudZMcP2eD/9tSjjZ3cq4i2HinMvH/FFSYoJz1GQrtTGufur Ga2nEgCle73A2yretagOdBpnHRJwmRFjiEFBd2KjiJMVB7iGvtJ2bRlaaDzL7z9K9lzE qMWYal0s5E4VDBTMNoxW+SZibleIJSGM6enjdyvPpsmi3vHI0Lb1c0hbaSoSGQaCaRtz +/QA== X-Gm-Message-State: AOAM5338ZRJ1GscuSYNJJJ1t33yk1uII95G5kxgqUWkTbD43gyg6Sm7B HNCbNBLZa+HpXqZIF0FAPNKZiR2TDRw= X-Google-Smtp-Source: ABdhPJwyXabFDQ3IWH0q0rpHtxZb3oftVYu1DFJDql/18ZPPObBObMy/T5slSaxo1JHCcCGjletcqg== X-Received: by 2002:a17:907:75c7:: with SMTP id jl7mr10811ejc.191.1615413340140; Wed, 10 Mar 2021 13:55:40 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:39 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:42 +0100 Message-Id: <20210310215446.1396386-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/23] dnn/dnn_backend_native_layer_conv2d: Check allocation 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- Why does DNN actually not use the ordinary error codes? libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index 94a07c1fdb..941330c895 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -228,6 +228,8 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera #if HAVE_PTHREAD_CANCEL thread_param = av_calloc(thread_num, sizeof(*thread_param)); + if (!thread_param) + return DNN_ERROR; thread_stride = (height - pad_size * 2) / thread_num; //create threads for (int i = 0; i < thread_num; i++){ From patchwork Wed Mar 10 21:54:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26331 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C3EDF44B799 for ; Wed, 10 Mar 2021 23:55:54 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AE9BF68ABD9; Wed, 10 Mar 2021 23:55:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C33E68AB82 for ; Wed, 10 Mar 2021 23:55:41 +0200 (EET) Received: by mail-ej1-f46.google.com with SMTP id e19so41902773ejt.3 for ; Wed, 10 Mar 2021 13:55:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=e82P049+YimJN626QPZroM0UXovvETCUM4vHdo3pqAE=; b=f48K5xLtmMyMk2gM0YeVMU5e7YP6NRhNL4/cCSjJRVkeNgD7hDXMmDvPqx3Gy42Oym 09m9Sk+ajBpHnzhYFauzW4JEhbO+JmMNgnfcPwlrB+KP4qPPDKgbK5X8RZCU5hqT7My8 8UPBsPx9oy9rMp6egrRvaH4VEpCCr1qirnT4jTmt0n9Cz+Gy0nkCToIuFeVlSPT+ScWq ihjImEIqWdmpM2L3Xxz9tFOdnhMTZ2DZjwvse1AliwOwATwy6qGU/vovOI3scwwDVyZr usZImV8MSKZhPp21k7oFmth7HnhSi3WZUzOpWi86OIySNzlkEpNDDAjS6ikBz1e4txmu 8pqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=e82P049+YimJN626QPZroM0UXovvETCUM4vHdo3pqAE=; b=tLPd62HIyHWTI7BPcn4gtkL0RY3xV7YVJVpq8W+vFhQdYOWX1erA32syaaZO+VUe1i FkfpR/gxHFSyWhXRfd6gs2sCWUv5vnF++Ak4IJrHAZnsP4IV+i+hw0Ahk6/GPrP7d/iF SnbFSmhELGj1ZY/UTnI8tvzxAu4gbwYifiARGPySHDuGVfzpeUISdPylkyocokl6JWYM KmRFqthS0cIxoP5aavQ7BGH/VD3AddOMgjk3j4D8w7JWGKIkvXv2rbX9i59pRTKnLGSq CmYs0UdK3wz1J/oyaejLORFJrLPG7KTCK8dmC2drIaC5clJNwOaEbxKdpxrpBSG8nwnj Ww6g== X-Gm-Message-State: AOAM533XCWtPBZWQ8YKeD0BrozQwFFHc6jUDRb8CNefiLbohjfIk0KP4 b96F+rHfXaTwqCVCqmdkVFJDGqN8gp0= X-Google-Smtp-Source: ABdhPJyV4cv8cpz9JyN58wEPPRZknalszJbyGmNtzi0tFyM0PLUuzDfVDQh5Qt/m0aQ5iZsu0YTp9Q== X-Received: by 2002:a17:907:77d4:: with SMTP id kz20mr15053ejc.93.1615413340829; Wed, 10 Mar 2021 13:55:40 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:40 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:43 +0100 Message-Id: <20210310215446.1396386-11-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/23] dnn/dnn_backend_native_layer_conv2d: Check thread creation for errors 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes Coverity issue #1473533. Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index 941330c895..44e5bdb5f7 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -190,7 +190,7 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera #if HAVE_PTHREAD_CANCEL int thread_num = (ctx->options.conv2d_threads <= 0 || ctx->options.conv2d_threads > av_cpu_count()) ? (av_cpu_count() + 1) : (ctx->options.conv2d_threads); - int thread_stride; + int ret = DNN_SUCCESS, thread_stride; ThreadParam *thread_param; #else ThreadParam thread_param = { 0 }; @@ -236,7 +236,12 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera thread_param[i].thread_common_param = &thread_common_param; thread_param[i].thread_start = thread_stride * i + pad_size; thread_param[i].thread_end = (i == thread_num - 1) ? (height - pad_size) : (thread_param[i].thread_start + thread_stride); - pthread_create(&thread_param[i].thread, NULL, dnn_execute_layer_conv2d_thread, &thread_param[i]); + if (pthread_create(&thread_param[i].thread, NULL, + dnn_execute_layer_conv2d_thread, &thread_param[i])) { + thread_num = i; + ret = DNN_ERROR; + break; + } } //join threads, res gets function return @@ -246,12 +251,14 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera //release memory av_free(thread_param); + + return ret; #else thread_param.thread_common_param = &thread_common_param; thread_param.thread_start = pad_size; thread_param.thread_end = height - pad_size; dnn_execute_layer_conv2d_thread(&thread_param); -#endif return DNN_SUCCESS; +#endif } From patchwork Wed Mar 10 21:54:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26332 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9A1BE44B799 for ; Wed, 10 Mar 2021 23:55:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8608D68ABE3; Wed, 10 Mar 2021 23:55:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F210968AB27 for ; Wed, 10 Mar 2021 23:55:41 +0200 (EET) Received: by mail-ej1-f42.google.com with SMTP id e19so41902809ejt.3 for ; Wed, 10 Mar 2021 13:55:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=ajahs6bg1BdK9agnUhazDcAnrNvVkh/vZVOSw0KA+Rk=; b=aRq2Zp7sVj3Np7w8V+me6GZkgRhGJC55cjGwzqngSx/Idak0JGgNYxeparLeBJdvHl tVm9WOp8ONW1ANxmWXXGJESiuQuVZxrLX53OqPwN3EgVFRC1iMFWkd8EBa6mJ+Sl3cRe 9TeNSiyQHFpmpMGyIWbxUGEcMkF8pI0ip04luJxbxXEgSIm6Sy0+teLXgbWu2aIjBOgq sCUVfYXUZdpt0pGH/TvLqvgS9C/YEA5CUhhznxFj1L7kuvCS5h23tZx2SNKFa9lHdGVZ a2I1LbdaPc1Mrd/dNnM2raJVVpcE1WSGJI51ZfYEJh+AzDnMlBazwVszS5uurOyvuPaJ FohA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=ajahs6bg1BdK9agnUhazDcAnrNvVkh/vZVOSw0KA+Rk=; b=uoAVVDVbzly4ZuqAiygxkOA2IztLjN7l3ggblexjfxDhFf/96nFZRJhYFckMq5tsdo 5UqPW2E8ZqLkjJmewA4u2Fxf+mJcQjh9AyIiGeqQ9oUehBWlhuOQ+iURRTpr1V+bRcPF OZl/irQAlI7ecZRMgLwsvl5fMIdld3bHNeUbFPZ7c1WCgjhshQlbIsNRPhuuaDpaCfEz dr8WNtTeddwCxRlHi0E2bidZlICPjBWXsyfZWuHm1ot+QD4kONGKBuzjW3z1Cakgacc7 qYqyJ2fr7DaZpr4bRCmSZiWBbf4USoRaSt0xt8wPmbQtC0CJ0/AMcGACJQEHtQhq2tbY zMyQ== X-Gm-Message-State: AOAM531RsFO+0FhdLUeQvd1PE1tPRNFfLYiGzqEQtXWjkr0wQUqYAzdy mOtWa3vkW6GsW5kr/o1lqENGR58yW+I= X-Google-Smtp-Source: ABdhPJxorvWV7XZWZ2uyhhJUOB7MTH+4/UWXGTaP7XcgKsb0ZTjnzKI2sR0lzdCvPaB3pN9jxgEHHA== X-Received: by 2002:a17:906:5689:: with SMTP id am9mr29675ejc.298.1615413341412; Wed, 10 Mar 2021 13:55:41 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:41 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:44 +0100 Message-Id: <20210310215446.1396386-12-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/23] dnn/dnn_backend_native_layer_conv2d: Don't pretend convolution can fail 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It can't; these are just remnants of commit 3c7cad69f233252e5178f7732baa0da950d74bbd which let the worker threads do the reallocation. Signed-off-by: Andreas Rheinhardt --- libavfilter/dnn/dnn_backend_native_layer_conv2d.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c index 44e5bdb5f7..f7f1ef9b6b 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_conv2d.c +++ b/libavfilter/dnn/dnn_backend_native_layer_conv2d.c @@ -180,7 +180,7 @@ static void * dnn_execute_layer_conv2d_thread(void *threadarg) output += conv_params->output_num; } } - return (void *)DNN_SUCCESS; + return NULL; } @@ -244,7 +244,6 @@ int ff_dnn_execute_layer_conv2d(DnnOperand *operands, const int32_t *input_opera } } - //join threads, res gets function return for (int i = 0; i < thread_num; i++){ pthread_join(thread_param[i].thread, NULL); } From patchwork Wed Mar 10 21:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26324 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3B95A44B799 for ; Wed, 10 Mar 2021 23:55:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2896668AB46; Wed, 10 Mar 2021 23:55:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CB9B168AB32 for ; Wed, 10 Mar 2021 23:55:42 +0200 (EET) Received: by mail-ed1-f41.google.com with SMTP id d13so64492edp.4 for ; Wed, 10 Mar 2021 13:55:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=qy5bAWiTjMwlHFtKI/qaVBFBUIVyuVbTRekWCgGhPVs=; b=SYdR+z6I8QIftN5G2uDDWFPzL80bNDBfs91GYjIV/YBsin9gNZBtsDBk/5gzSaqJVW /r71lrnrrNcZli6mW5HN4Y2g6p9/Z4OR/vKO11M75wbFAtjBOh2qPC1x6nfnzwF6LHQk FTeXRIWhvwAtM7hCjredemDJ28SNHMnu4j7Eq3JT1Pnyg6ye43r0kC1SdsLFSW3p/Z2E n+v7+W7o2OeCuF9G34qEhWW1U7P54uLw+UPDoGYpQ2t/HTDsfgC0vAhAivG+O62xpSq+ hzQ08yFSn7c+WYEJCrmCyHHXpxR3+XXoGdsvGhuXXvX5qgre8PVlLPZrK0UYiqM4ffOB m4VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=qy5bAWiTjMwlHFtKI/qaVBFBUIVyuVbTRekWCgGhPVs=; b=p/teoncMqMfoRe49ZApxpO4zf4LT5nOHKbk52LXAT0OXXMsqadzlG19EwhdG8YKT0M 6FhsnAcz4t6fpEkT9incObFZv5/0IAPL1pWrSKPDFZKmsprSaEH9VFTVfew7+ZReTn1y yUQsXGO0Ko8H1mt0+oFjgB7mqw9h54ee1RSwrnsehaml18bvcwUM+GZT/6F19knfBrlZ p5k+yqYULy3lsEzINsOGsV/HsCewGYc5/WhTRyommpy45/3hKNnI+6gcYu9V0DG52ikk F29XtL1DBBZpPtWTDItOWHaUJWRvtOAmHm/O7eA0uVje51Ts1OPTUEfyD9RYtWx8MMY1 2ASQ== X-Gm-Message-State: AOAM533/hpKj/uVmOFTS7oWNUkxd88h2GzKKxDgQQKvdCEeSdXXg1+L1 W3svRm2JrJd8Thh6hgxn0u9etgelfAQ= X-Google-Smtp-Source: ABdhPJzQZtGHxjMTcHZvRnFN8JhYFXFlj8AUTt7wWiQNwiJRGdVE/n31F1wAhkMTuc1Qs7QbEC+N5A== X-Received: by 2002:a05:6402:1c98:: with SMTP id cy24mr5514026edb.296.1615413342044; Wed, 10 Mar 2021 13:55:42 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:41 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:45 +0100 Message-Id: <20210310215446.1396386-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/23] dnn/dnn_backend_native_layer_mathbinary: Fix leak upon error 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes Coverity issue #1473568. Signed-off-by: Andreas Rheinhardt --- .../dnn/dnn_backend_native_layer_mathbinary.c | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c index c116188bab..1c33b4633d 100644 --- a/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c +++ b/libavfilter/dnn/dnn_backend_native_layer_mathbinary.c @@ -100,20 +100,17 @@ static void math_binary_not_commutative(FunType pfun, const DnnLayerMathBinaryPa } int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num) { - DnnLayerMathBinaryParams *params; + DnnLayerMathBinaryParams params = { 0 }; int dnn_size = 0; int input_index = 0; - params = av_malloc(sizeof(*params)); - if (!params) - return 0; - params->bin_op = (int32_t)avio_rl32(model_file_context); + params.bin_op = (int32_t)avio_rl32(model_file_context); dnn_size += 4; - params->input0_broadcast = (int32_t)avio_rl32(model_file_context); + params.input0_broadcast = (int32_t)avio_rl32(model_file_context); dnn_size += 4; - if (params->input0_broadcast) { - params->v = av_int2float(avio_rl32(model_file_context)); + if (params.input0_broadcast) { + params.v = av_int2float(avio_rl32(model_file_context)); } else { layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context); if (layer->input_operand_indexes[input_index] >= operands_num) { @@ -123,10 +120,10 @@ int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, } dnn_size += 4; - params->input1_broadcast = (int32_t)avio_rl32(model_file_context); + params.input1_broadcast = (int32_t)avio_rl32(model_file_context); dnn_size += 4; - if (params->input1_broadcast) { - params->v = av_int2float(avio_rl32(model_file_context)); + if (params.input1_broadcast) { + params.v = av_int2float(avio_rl32(model_file_context)); } else { layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context); if (layer->input_operand_indexes[input_index] >= operands_num) { @@ -138,11 +135,13 @@ int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, layer->output_operand_index = (int32_t)avio_rl32(model_file_context); dnn_size += 4; - layer->params = params; if (layer->output_operand_index >= operands_num) { return 0; } + layer->params = av_memdup(¶ms, sizeof(params)); + if (!layer->params) + return 0; return dnn_size; } From patchwork Wed Mar 10 21:54:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26326 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3080A44B799 for ; Wed, 10 Mar 2021 23:55:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1DE4668AB55; Wed, 10 Mar 2021 23:55:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6A02A68AB43 for ; Wed, 10 Mar 2021 23:55:43 +0200 (EET) Received: by mail-ej1-f54.google.com with SMTP id r17so41811922ejy.13 for ; Wed, 10 Mar 2021 13:55:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=+BcAGIHcYeJDYSi8JlVlvZpBKK8fraSS/LEw/Q/OA2c=; b=N/Jzb551TdM9cLmY9IJG2whKDKUAya0jj3wLtq8WOrrX8gXKh8+ORPX8wr+ZViYlzg Aszp51PrZfefmYIQxrAfOdmf8gqO7snrxikRbx6jGV2q/PqisVnln1FO24QZUINYXNLd 5TEtxemlBqUVzHs2Ynir6Cx+R1a+gtsj8e8vgTVaiN9sLrVSvAWj/DQdkZgfFG1V9Vju iL6syxWqpyth1rCuuEjIp5t+ZUZRXNuUVt0Er5yz6mpAxOAQ6peLYAP8fE8UV+W78os7 nI6rM8IKagsGdSUkmAaunDvSZ7DgyED3voXP2lhGtv6v3xjGV5TGKXAY7D+kLqP6cwOg 4DIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=+BcAGIHcYeJDYSi8JlVlvZpBKK8fraSS/LEw/Q/OA2c=; b=I/crQ/Pa4/64yp3oB52ngMGRvw3LKgmfX8LiWRJcui6UGkzw+JWN0IwRgQpoeaQDRT A4Gpo+iGqS19QoKYOie/lSAq9A98J2N3obSsIMF87gjbof3DJeYRUnjdN26jIAdxIiSI u7xj7/VxqteY6hj3ywrClOZRzu5q95cuIvh57aK0r0KDlcT9JlCE0G1Y8E3Dsnt6DATZ Vn9qkN2fUpHqZlaChdnxzT16M+793wt6B2i1qbQiFi64XIhzuGjrTUzWBUVByrzslP+n vN0dLeUpnBWIbu2Xaz+f2h9XrXZCqZyL0WqRYwA8Icbl6XnriYsl4X2hGPe6A73qxWWF caFQ== X-Gm-Message-State: AOAM530xHn9f0oUnj6fzTP2/aAkA2OWmawNaT9sEaz0oqscGvASnAf2L GzHsgZCIKbR6EtRdryD1g400+8q64yg= X-Google-Smtp-Source: ABdhPJyLWcDYhytme5a08QC/+9AfMIHqvCS/OwV1JSN/DZjZrCRLDZnvtDEZWF8IUP2AQfuCOMOlTw== X-Received: by 2002:a17:906:1907:: with SMTP id a7mr38675eje.142.1615413342703; Wed, 10 Mar 2021 13:55:42 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id m10sm351993ejx.10.2021.03.10.13.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 13:55:42 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Mar 2021 22:54:46 +0100 Message-Id: <20210310215446.1396386-14-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> References: <20210310010601.1142819-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/23] avcodec/pngdec: Fix memleak by postponing allocation 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes Coverity ticket #1322342. Signed-off-by: Andreas Rheinhardt --- It seems to me that this temporary buffer is actually unneeded: One just needs to use the new frame as destination for blending and then overwrite the new frame's data outside the processed rectangle with the data from the old frame. Or am I wrong about this? libavcodec/pngdec.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index a5a71ef161..63c22063d9 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -1080,10 +1080,6 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, return AVERROR_PATCHWELCOME; } - buffer = av_malloc_array(s->image_linesize, s->height); - if (!buffer) - return AVERROR(ENOMEM); - ff_thread_await_progress(&s->last_picture, INT_MAX, 0); // need to reset a rectangle to background: @@ -1099,7 +1095,9 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, } } - memcpy(buffer, s->last_picture.f->data[0], s->image_linesize * s->height); + buffer = av_memdup(s->last_picture.f->data[0], s->image_linesize * s->height); + if (!buffer) + return AVERROR(ENOMEM); // Perform blending if (s->blend_op == APNG_BLEND_OP_SOURCE) {